ON THIS PAGE
Examples: Alarms
Alarm templates and associated items (SNMP managers, alarm email lists) are created and managed in a similar way as inventory items. This chapter contains XML and NETCONF code for defining such entities in Routing Active Testing through the NETCONF & YANG API and for retrieving lists of the items defined.
Alarm Email Lists
Creating an Alarm Email List
with manager.connect(host=args.host, port=args.port, username=args.username,
password=args.password, hostkey_verify=False) as m:
# Create email list in account
xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<accounts xmlns="http://ncc.netrounds.com">
<account>
<name>{account}</name>
<alarm-email-lists>
<alarm-email-list>
<name>{name}</name>
<addresses>{addresses1}</addresses>
<addresses>{addresses2}</addresses>
</alarm-email-list>
</alarm-email-lists>
</account>
</accounts>
</config>""".format(account=args.netrounds_account,
name='email list',
addresses1='thranduil@example.com',
addresses2='nimrodel@example.com')
print m.edit_config(target='running', config=xml)Retrieving All Alarm Email Lists
with manager.connect(host=args.host, port=args.port, username=args.username,
password=args.password, hostkey_verify=False) as m:
# Get email lists in account
xml = """<accounts xmlns="http://ncc.netrounds.com">
<account>
<name>{account}</name>
<alarm-email-lists></alarm-email-lists>
</account>
</accounts>""".format(account=args.netrounds_account)
# Convert to ElementTree object
ele = to_ele(m.get_config(source='running', filter=('subtree', xml)).data_xml)
# Convert back to XML string and print
print to_xml(ele, encoding='UTF-8', pretty_print=True)SNMP Managers
Creating an SNMP Manager
with manager.connect(host=args.host, port=args.port, username=args.username,
password=args.password, hostkey_verify=False) as m:
# Create SNMP manager in account (version 2c)
xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<accounts xmlns="http://ncc.netrounds.com">
<account>
<name>{account}</name>
<snmp-managers>
<snmp-manager>
<name>{name}</name>
<ip>{ip}</ip>
<version>{version}</version>
<community>{community}</community>
</snmp-manager>
</snmp-managers>
</account>
</accounts>
</config>""".format(account=args.netrounds_account,
version='2c',
ip='8.8.8.8',
name='snmp manager',
community='my community string')
# Note: The user can also create a version 3 SNMP manager with the following parameters:
# <engine-id>{engine_id}</engine-id>
# <user-name>{user_name}</user-name>
# <security>{security}</security>
# <auth-password>{auth_password}</auth-password>
# <priv-password>{priv_password}</priv-password>
print m.edit_config(target='running', config=xml)Retrieving All SNMP Managers
with manager.connect(host=args.host, port=args.port, username=args.username,
password=args.password, hostkey_verify=False) as m:
# Get SNMP managers in account
xml = """<accounts xmlns="http://ncc.netrounds.com">
<account>
<name>{account}</name>
<snmp-managers></snmp-managers>
</account>
</accounts>""".format(account=args.netrounds_account)
# Convert to ElementTree object
ele = to_ele(m.get_config(source='running', filter=('subtree', xml)).data_xml)
# Convert back to XML string and print
print to_xml(ele, encoding='UTF-8', pretty_print=True)Alarm Templates
Creating an Alarm Template
# Note: This example requires existing an SNMP manager and alarm email list in order to work
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m:
# Create alarm template in account
xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<accounts xmlns="http://ncc.netrounds.com">
<account>
<name>{account}</name>
<alarm-templates>
<alarm-template>
<name>{name}</name>
<email>{email}</email>
<snmp>{snmp}</snmp>
<action>{action}</action>
<window-size>{window_size}</window-size>
<interval>{interval}</interval>
<send-only-once>{send_only_once}</send-only-once>
<snmp-trap-per-stream>{snmp_trap_per_stream}</snmp-trap-per-stream>
<thr-es-critical>{thr_es_critical}</thr-es-critical>
<thr-es-critical-clear>{thr_es_critical_clear}</thr-es-critical-clear>
<thr-es-major>{thr_es_major}</thr-es-major>
<thr-es-major-clear>{thr_es_major_clear}</thr-es-major-clear>
<thr-es-minor>{thr_es_minor}</thr-es-minor>
<thr-es-minor-clear>{thr_es_minor_clear}</thr-es-minor-clear>
<thr-es-warning>{thr_es_warning}</thr-es-warning>
<thr-es-warning-clear>{thr_es_warning_clear}</thr-es-warning-clear>
</alarm-template>
</alarm-templates>
</account>
</accounts>
</config>""".format(account=args.netrounds_account,
name='template',
email='email list',
snmp='snmp manager',
action='some action string',
window_size=60,
interval=300,
send_only_once='false',
snmp_trap_per_stream='false',
thr_es_critical=9,
thr_es_critical_clear=8,
thr_es_major=7,
thr_es_major_clear=6,
thr_es_minor=5,
thr_es_minor_clear=4,
thr_es_warning=3,
thr_es_warning_clear=2)
# Note: The user can also provide additional parameters:
# <no-data-severity>{no_data_severity}</no-data-severity>
# <no-data-timeout>{no_data_timeout}</no-data-timeout>
print m.edit_config(target='running', config=xml)Retrieving All Alarm Templates
with manager.connect(host=args.host, port=args.port, username=args.username,
password=args.password, hostkey_verify=False) as m:
# Get alarm templates in account
xml = """<accounts xmlns="http://ncc.netrounds.com">
<account>
<name>{account}</name>
<alarm-templates></alarm-templates>
</account>
</accounts>""".format(account=args.netrounds_account)
# Convert to ElementTree object
ele = to_ele(m.get_config(source='running', filter=('subtree', xml)).data_xml)
# Convert back to XML string and print
print to_xml(ele, encoding='UTF-8', pretty_print=True)