ON THIS PAGE
Examples: Alarms
Monitors can have alarms associated with them. This section explains how to do the following through the REST API:
- Creating alarm templates
- Setting up SNMP managers and lists of email recipients, specifying where to send alarms when they are triggered
We will begin with the alarm recipients, as these are a prerequisite when defining an alarm template. We then proceed to show how to create such templates, which among other things hold the trigger conditions for alarms.
Instances of alarms cannot be created in isolation through the REST API. Rather, alarm instances are created in the course of creating a monitor (most conveniently by referring to an alarm template, but optionally without doing so), as described in the section Creating a Monitor with an Alarm. However, you can perform some operations on alarm instances through the API:
- list alarm instances
- retrieve an individual alarm instance
- suppress an alarm instance so that it will never trigger, even if thresholds are exceeded
- delete an alarm instance.
Alarm Email Lists
Creating an Alarm Email List
# Request settings url = '%s/accounts/%s/alarm_emails/' % (args.ncc_url, args.account) # Parameter settings for alarm email list json_data = json.dumps({ "addresses": [ # Email addresses to include in list "a@a.com" ], "name": "Email list 1" }) # Create alarm email list response = requests.post(url=url, data=json_data, headers={ 'API-Token': args.token, 'Accept': 'application/json; indent=4', 'Content-Type': 'application/json', })
Retrieving All Alarm Email Lists
Here is how to retrieve a list of all alarm email lists and see what IDs they have been assigned.
# Request settings # NOTE: User is able to pass additional parameters as a query string ?limit=100&offset=111: # limit: Changes number of elements returned from API # offset: Changes element from which results will be returned url = '%s/accounts/%s/alarm_emails/%s' % (args.ncc_url, args.account, args.query_params) # Get list of alarm emails response = requests.get(url=url, headers={'API-Token': args.token})
SNMP Managers
Creating an SNMP Manager
The URL should be defined as shown below.
# Request settings url = '%s/accounts/%s/snmp_managers/' % (arg.ncc_url, args.account)
To create a version 2c SNMP manager, use the following settings:
# Parameter settings for SNMP version 2c json_data = json.dumps({ "community": "Community string", "ip": "8.8.8.8", "version": "2c" })
To create a version 3 SNMP manager, use the following settings:
# Parameter settings for SNMP Manager in version 3 json_data = json.dumps({ "auth_password": "12345678", "engine_id": "080005f85050000001", "ip": "8.8.8.8", "priv_password": "12345678", "security": "no_auth_no_priv", "user_name": "my_user_name", "version": "3", "name": "SNMP manager" }) # Create SNMP manager response = requests.post(url=url, data=json_data, headers={ 'API-Token': args.token, 'Accept': 'application/json; indent=4', 'Content-Type': 'application/json', })
Retrieving All SNMP Managers
Here is how to retrieve a list of all SNMP managers and see what IDs they have been assigned.
# Request settings # NOTE: User is able to pass additional parameters as a query string ?limit=100&offset=111: # limit: Changes number of elements returned from API # offset: Changes element from which results will be returned url = '%s/accounts/%s/snmp_managers/%s' % (args.ncc_url, args.account, args.query_params) # Get list of SNMP managers response = requests.get(url=url, headers={'API-Token': args.token})
Alarm Templates
Creating an Alarm Template
In practice, probably only one of email
and snmp
will be used.
# Request settings url = '%s/accounts/%s/alarm_templates/' % (args.ncc_url, args.account) # Parameter settings for alarm template json_data = json.dumps({ "action": "", "email": 1, # ID of email list previously defined "interval": 300, "name": "Alarm template", "snmp": 1, # ID of SNMP manager previously defined "thr_es_critical": 10, "thr_es_critical_clear": 9, "thr_es_major": 8, "thr_es_major_clear": 7, "thr_es_minor": 6, "thr_es_minor_clear": 5, "thr_es_warning": 4, "thr_es_warning_clear": 3, "window_size": 60, "send_only_once": False, "no_data_timeout": 1800, "snmp_trap_per_stream": False, # Set this to True to send SNMP traps per stream "no_data_severity": 1 # CLEAR = 0 | WARNING = 1 | MINOR = 2 | MAJOR = 3 | CRITICAL = 4 }) # Create alarm template response = requests.post(url=url, data=json_data, headers={ 'API-Token': args.token, 'Accept': 'application/json; indent=4', 'Content-Type': 'application/json', })
Retrieving All Alarm Templates
# Request settings # NOTE: User is able to pass additional parameters as a query string ?limit=100&offset=111: # limit: Changes number of elements returned from API # offset: Changes element from which results will be returned url = '%s/accounts/%s/alarm_templates/%s' % (args.ncc_url, args.account, args.query_params) # Get list of alarm templates response = requests.get(url=url, headers={'API-Token': args.token}) print 'Status code: %s' % response.status_code print json.dumps(response.json(), indent=4)
Modifying an Existing Alarm Template
If you need to adjust some settings in an alarm template, you can do so as follows:
# Request settings url = '%s/accounts/%s/alarm_templates/%s/' % (args.ncc_url, args.account, args.alarm_template_id) # JSON content json_data = json.dumps({ # Same list of parameters as when creating the template "action": "", "email": 2, # ID of email list "interval": 600, "name": "Alarm template", "snmp": 2, # ID of SNMP manager "thr_es_critical": 20, "thr_es_critical_clear": 9, "thr_es_major": 8, "thr_es_major_clear": 7, "thr_es_minor": 6, "thr_es_minor_clear": 5, "thr_es_warning": 4, "thr_es_warning_clear": 3, "window_size": 60, "send_only_once": False, "no_data_timeout": 1800, "snmp_trap_per_stream": False, "no_data_severity": 1 }) # Update alarm template response = requests.put(url=url, data=json_data, headers={ 'API-Token': args.token, 'Accept': 'application/json; indent=4', 'Content-Type': 'application/json', })