ESA API 1-0 Getting Started Guide
ESA API 1-0 Getting Started Guide
Guide
Release 1.0
Published: January 27, 2015
Contents
• Overview of Cisco AsyncOS API for Email, page 1
• Prerequisites for Using AsyncOS API, page 2
• Enabling AsyncOS API, page 2
• AsyncOS API Authentication and Authorization, page 3
• AsyncOS API Requests and Responses, page 4
• AsyncOS API Capabilities, page 7
• Troubleshooting AsyncOS API, page 12
• AsyncOS API Reference, page 14
Procedure
Note You can enable AsyncOS API on any IP interface. However, Cisco recommends that you enable
AsyncOS API on the Management interface.
Step 4 Under AsyncOS API (Monitoring) section, depending on your requirements, select HTTP, HTTPS, or
both and the ports to use.
If you have selected HTTPS and you want to use your own certificate for secure communication, see
Securely Communicating with AsyncOS API, page 3.
Note Cisco recommends that you always use HTTPS in the production environment. Use HTTP only
for troubleshooting and testing the API.
You can also enable the AsyncOS API using the interfaceconfig command in CLI.
Note Do not perform this procedure if you are already running the web interface over HTTPS and using your
own certificate for secure communication. AsyncOS API uses the same certificate as web interface, for
communicating over HTTPS.
Procedure
Step 1 Setup a certificate using the Network > Certificates page on web interface or the certconfig command
in the CLI. For instructions, refer Cisco AsyncOS for Email User Guide or Online Help.
Step 2 Change the HTTPS certificate used by the IP interface to your certificate using the Network > IP
Interfaces page on web interface or the interfaceconfig command in CLI. For instructions, refer Cisco
AsyncOS for Email User Guide or Online Help.
Step 3 Submit and commit your changes.
Authorization
Email Security appliance users with the following roles can access the AsyncOS API:
• Administrator
• Read-Only Operator
• Operator
• Guest
Note Users from centralized authentication system (LDAP or RADIUS directory) are not authorized to access
the Cisco AsyncOS API for Email. If an LDAP or RADIUS directory user attempts to access the API,
the API sends a 401 error message.
Authentication
API users must submit an Email Security appliance username and password with all the requests to the
API in base64-encoded format. If a request does not include valid credentials in the Authorization
header, the API sends a 401 error message.
You can use any base64 library to convert your credentials into base64-encoded format. The following
table shows an example of base64-encoded credentials:
Item Value
Username administrator
Password Password$123
Credentials administrator:Password$123
Note API requests are case sensitive and should be entered as shown in this guide.
Request Structure
The following table lists the types of request operations that you can use with the AsyncOS API.
2. Links or Data
– Links. The list of next level resources in the
hierarchy.
Example
"links":
{"percentage_ram_utilization":
"Percentage...}
• 401
• 404
• 406
• 413
• 414
• 500
• 501
• 505
For descriptions of these HTTP response codes, refer the following RFCs:
• RFC1945
• RFC7231
Example
Sample Request
GET /api/v1.0/health HTTP/1.0
User-Agent: curl/7.30.0
Host: mail.example.com:8080
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Accept: application/json
Sample Response
HTTP/1.0 200 OK
Server: EmailAPI/1.0
Date: Wed, 02 Jul 2014 05:07:50 GMT
Content-type: application/json
Content-Length: 246
Connection: close
{
"data":{
"percentage_ram_utilization":10,
"percentage_diskio":20,
"resource_conservation":3,
"messages_in_workqueue":189,
"messages_in_pvo_quarantines":12,
"percentage_swap_utilization":2.0,
"percentage_queue_utilization":5.0,
"percentage_cpu_load":12
},
"uri":"/api/v1.0/health/"
}
Note For more information about these health parameters, access the API inline help using the following URI:
https://{appliance}:{port}/api/v1.0/health/help. See Accessing Cisco AsyncOS API for Email
Inline Help, page 12.
• Top-N Report. This report category counts various events in your appliance against an entity (IP
address, domain name, and so on) for a specified duration and lists the top-N events, where N is a
user specified value. Examples are mail_content_filter_incoming and
mail_dmarc_incoming_traffic_summary.
• Query-based Report. This report category counts various events in your appliance against a
user-specified entity (IP address, domain name, and so on) for a specified duration. Examples are
mail_authentication_incoming_domain and mail_content_filter_outgoing.
For a list of reports under each category, see Statistical Reports, page 14.
Description Retrieve various statistical reports from the Email Security appliance.
Synopsis GET /api/v1.0/stats/report?resource_attribute
GET /api/v1.0/stats/report/counter?resource_attribute
Supported Resource Simple Report • time_range. Use this attribute to retrieve report(s) for a specified
Attributes duration. This attribute can assume the following values:
– 1h - Aggregate report(s) for the last one hour
– 1d - Aggregate report(s) for the last one day
– duration=YYYY-MM-DDThh:mmTZD/YYYY-MM-DDThh:mmTZD -
Aggregate report(s) for the specified duration. Supported values
of TZD are Z, +hh:mm, or -hh:mm.
Top-N Report • time_range. Use this attribute to retrieve report(s) for a specified
duration. This attribute can assume the following values:
– 1h - Aggregate report(s) for the last one hour
– 1d - Aggregate report(s) for the last one day
– duration=YYYY-MM-DDThh:mmTZD/YYYY-MM-DDThh:mmTZD -
Aggregate report(s) for the specified duration. Supported values
of TZD are Z, +hh:mm, or -hh:mm.
• max=n. Use this attribute to limit the number of results returned by the
report. n is the number of results that you want the report to return and
can assume values from 1 through 1000.
Query-based Report • time_range. Use this attribute to retrieve report(s) for a specified
duration. This attribute can assume the following values:
– 1h - Aggregate report(s) for the last one hour
– 1d - Aggregate report(s) for the last one day
– duration=YYYY-MM-DDThh:mmTZD/YYYY-MM-DDThh:mmTZD -
Aggregate report(s) for the specified duration. Supported values
of TZD are Z, +hh:mm, or -hh:mm.
• entity=value. Use this attribute to retrieve reports based on a
specified entity such as email address, IP address, and so on. You can
choose whether to exactly match the specified text or look for items
starting with the specified text (for instance, starts with "ex" will
match "example.com").
Note The definition of this attribute varies from report type to report
type. For the permissible values of this attribute, see Statistical
Reports, page 14.
To retrieve items starting with the specified text, you must use this
attribute in conjunction with starts_with attribute, for example,
entity=us& starts_with=true.
• max=n. Use this attribute to limit the number of results returned by the
report. n is the number of results that you want the report to return and
can assume values from 1 through 1000.
Note You cannot use the entity and max=n attributes in the same
request.
Note Use an AND (&) operator to use multiple attributes, for example:
https://{appliance}:{port}/api/v1.0/stats/report/counter?attribute1&attribute2.
Note For more information about statistical reports and counters, access the API inline help. See Accessing
Cisco AsyncOS API for Email Inline Help, page 12.
Examples
• Simple Report Type, page 10
• Top-N Report Type, page 11
• Query-based Report Type, page 11
The following example shows how to retrieve aggregate Incoming Mail Summary report for the last one
day.
Sample Request
GET /api/v1.0/stats/mail_incoming_traffic_summary?1d HTTP/1.0
User-Agent: curl/7.30.0
Host: mail.example.com:8080
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Accept: application/json
Sample Response
HTTP/1.0 200 OK
Server: EmailAPI/1.0
Date: Tue, 15 Jul 2014 08:26:46 GMT
Content-type: application/json
Content-Length: 461
Connection: close
{
"data":{
"verif_decrypt_success":0,
"detected_virus":1396438,
"threat_content_filter":106728,
"blocked_invalid_recipient":209054,
"verif_decrypt_fail":0,
"marketing_mail":0,
"detected_amp":0,
"ims_spam_increment_over_case":0,
"total_recipients":827216461,
"detected_spam":1265606,
"total_clean_recipients":1977205,
"blocked_dmarc":0,
"malicious_url":14006,
"total_threat_recipients":825239256,
"blocked_reputation":822261430
},
"uri":"/api/v1.0/stats/mail_incoming_traffic_summary?1d"
}
The following example shows how to retrieve top five subjects of high volume mails for a specified
duration.
Sample Request
GET
/api/v1.0/stats/mail_subject_stats?duration=2014-04-23T00:00-00:00/2014-10-21T00:00-00:00&
max=5 HTTP/1.0
User-Agent: curl/7.30.0
Host: mail.example.com:8080
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Accept: application/json
Sample Response
HTTP/1.0 200 OK
Server: EmailAPI/1.0
Date: Tue, 15 Jul 2014 08:26:46 GMT
Content-type: application/json
Content-Length: 182
Connection: close
{
"data":{
"num_msgs":{
"Buying judgments":44584,
"Additional Income":39691,
"Why pay more?":46044,
"Message contains":50460,
"Off shore":56954
}
},
"uri":"/api/v1.0/stats/mail_subject_stats?duration=2014-04-23T00:00-00:00/2014-10-21T00:00
-00:00&max=5"
}
The following example shows how to retrieve aggregate Outgoing Sender report for IP addresses starting
with “2001::6” for a specified duration.
Sample Request
GET
/api/v1.0/stats/mail_sender_ip_hostname_detail?duration=2014-04-23T00:00-00:00/2014-10-21T
00:00-00:00&entity=2001::63&starts_with=true HTTP/1.0
User-Agent: curl/7.30.0
Host: mail.example.com:8080
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Accept: application/json
Sample Response
HTTP/1.0 200 OK
Server: EmailAPI/1.0
{
"data":{
"2001::63":{
"detected_virus":2,
"threat_content_filter":0,
"total_dlp_incidents":0,
"total_clean_recipients":4372,
"total_recipients_processed":4374,
"detected_spam":0,
"total_threat_recipients":2
}
"2001::6":{
"detected_virus":2,
"threat_content_filter":0,
"total_dlp_incidents":0,
"total_clean_recipients":1232,
"total_recipients_processed":1234,
"detected_spam":0,
"total_threat_recipients":2
}
},
"uri":"/api/v1.0/stats/mail_sender_ip_hostname_detail?duration=2014-04-23T00:00-00:00/2014
-10-21T00:00-00:00&entity=2001::6&starts_with=true"
}
API Logs
Subscribe to the API logs using System Administration > Log Subscriptions. For instructions, see
Cisco AsyncOS for Email User Guide or Online Help.
The following are some of the events that are logged in the API logs:
• API has started or stopped
• Connection to the API failed or closed (after providing response)
• Authentication succeeded or failed
• Request contains errors
• Error while communicating network configuration changes with AsyncOS API
Alerts
Ensure that the appliance is configured to send you alerts related to AsyncOS API. You will receive alerts
when:
Alert About Network Configuration or Certificate Changes Not Communicated to AsyncOS API
Problem You receive a critical alert stating that the network configuration or certificate changes made
using web interface or CLI are not communicated to the API.
Solution Try the following:
• Restart the appliance.
• If the problem persists, contact TAC.
Statistical Reports
The following table provides a list of categories of statistical reports and the reports under each category.