Skip to content

Instantly share code, notes, and snippets.

@idqdq
Created January 10, 2022 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idqdq/09dfecedd60795a352fc9e75ab7ce31f to your computer and use it in GitHub Desktop.
Save idqdq/09dfecedd60795a352fc9e75ab7ce31f to your computer and use it in GitHub Desktop.
zabbix templates and a pyscript mentioned in the article https://habr.com/en/post/349128
#!/usr/bin/python
import sys
from pysnmp.hlapi import *
import json
def findsubstrings(s):
la = s.split('.')
lb = la[1:]
if '6' in lb: # looking for a delimiter. 6 for EX or 10 for SRX
i = lb.index('6')
elif '10' in lb:
i = lb.index('10')
else:
sys.stderr.write("delimiter nor 6 ot 10")
exit(0)
l1 = lb[:i]
l2 = lb[i+1:]
param2 = ''.join([chr(int(i)) for i in l1])
param3 = ''.join([chr(int(i)) for i in l2])
return param2, param3
eRR = '{ data: ["Error parsing arguments"]}\n'
if len(sys.argv)!=3:
sys.stderr.write(eRR)
exit()
hostname = sys.argv[1]
community=sys.argv[2]
jnxRpmResSumSent = "1.3.6.1.4.1.2636.3.50.1.2.1.2"
l = []
# init snmpwalk over jnxRpmResSumSent MIB Object
varBind = nextCmd(SnmpEngine(), CommunityData(community), UdpTransportTarget((hostname, 161)),
ContextData(), ObjectType(ObjectIdentity(jnxRpmResSumSent)),
lexicographicMode=False)
# do snmmpwalk and collect an rpm specific substring
for res in varBind:
s = str(res[3][0][0])[len(jnxRpmResSumSent)+1:-2]
l.append(s)
# lets make values inside the list l uniq
u = set(l)
jsonData=[]
for param1 in u:
d={}
param2, param3 = findsubstrings(param1)
d["{#RPMUUID}"] = param1
d["{#RPMOWNER}"] = param2
d["{#RPMTEST}"] = param3
jsonData.append(d)
print (json.dumps({"data": jsonData}, indent=4))
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.4</version>
<date>2022-01-10T11:20:37Z</date>
<groups>
<group>
<name>Juniper</name>
</group>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template Juniper EX RPM</template>
<name>Template Juniper EX RPM</name>
<description/>
<groups>
<group>
<name>Juniper</name>
</group>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>Juniper RPM Discovery</name>
<type>10</type>
<snmp_community/>
<snmp_oid/>
<key>discovery_juniper_rpm.py[{HOST.CONN},{$SNMP_COMMUNITY}]</key>
<delay>5m</delay>
<status>0</status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype>0</evaltype>
<formula/>
<conditions/>
</filter>
<lifetime>30d</lifetime>
<description>Discover all RPM (Real time performance monitoring) tests that is being performed on a Juniper Network Device&#13;
the scripts returns 3 macroses:&#13;
{#RPMUUID} = &quot;3.73.83.80.49.6.84.69.83.84.49&quot; - a part of OID uniq for an RPM&#13;
{#RPMOWNER} = &quot;ISP1&quot; - RPM Owner name&#13;
{#RPMTEST} = &quot;Test1&quot; - RPM Probe name</description>
<item_prototypes>
<item_prototype>
<name>RTT {#RPMOWNER} test {#RPMTEST}</name>
<type>4</type>
<snmp_community>{$SNMP_COMMUNITY}</snmp_community>
<snmp_oid>1.3.6.1.4.1.2636.3.50.1.1.1.2.{#RPMUUID}.1</snmp_oid>
<key>delay[&quot;{#RPMUUID}&quot;]</key>
<delay>30s</delay>
<history>1w</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>ms</units>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>1</type>
<params>0.001</params>
</step>
</preprocessing>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
<item_prototype>
<name>Jitter {#RPMOWNER} test {#RPMTEST}</name>
<type>4</type>
<snmp_community>{$SNMP_COMMUNITY}</snmp_community>
<snmp_oid>1.3.6.1.4.1.2636.3.50.1.1.1.2.{#RPMUUID}.2</snmp_oid>
<key>jitter[&quot;{#RPMUUID}&quot;]</key>
<delay>30s</delay>
<history>1w</history>
<trends>365d</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units>ms</units>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>1</type>
<params>0.001</params>
</step>
</preprocessing>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
<item_prototype>
<name>PacketLoss {#RPMOWNER} test {#RPMTEST}</name>
<type>4</type>
<snmp_community>{$SNMP_COMMUNITY}</snmp_community>
<snmp_oid>1.3.6.1.4.1.2636.3.50.1.2.1.4.{#RPMUUID}.2</snmp_oid>
<key>PacketLoss[&quot;{#RPMUUID}&quot;]</key>
<delay>30s</delay>
<history>1w</history>
<trends>365d</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units>%</units>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>1</type>
<params>0.000001</params>
</step>
</preprocessing>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Template Juniper EX RPM:PacketLoss[&quot;{#RPMUUID}&quot;].last()}&gt;7</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>{#RPMOWNER} PacketLoss: {ITEM.LASTVALUE}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>4</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes>
<graph_prototype>
<name>{#RPMOWNER}:{#RPMTEST} GRAPH</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>0</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>1A7C11</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template Juniper EX RPM</host>
<key>delay[&quot;{#RPMUUID}&quot;]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>0</drawtype>
<color>F63100</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template Juniper EX RPM</host>
<key>jitter[&quot;{#RPMUUID}&quot;]</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>0</drawtype>
<color>2774A4</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template Juniper EX RPM</host>
<key>PacketLoss[&quot;{#RPMUUID}&quot;]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
</graph_prototypes>
<host_prototypes/>
<jmx_endpoint/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens>
<screen>
<name>Juniper RPM Screen</name>
<hsize>1</hsize>
<vsize>1</vsize>
<screen_items>
<screen_item>
<resourcetype>20</resourcetype>
<width>500</width>
<height>100</height>
<x>0</x>
<y>0</y>
<colspan>1</colspan>
<rowspan>1</rowspan>
<elements>0</elements>
<valign>0</valign>
<halign>0</halign>
<style>0</style>
<url/>
<dynamic>0</dynamic>
<sort_triggers>0</sort_triggers>
<resource>
<name>{#RPMOWNER}:{#RPMTEST} GRAPH</name>
<host>Template Juniper EX RPM</host>
</resource>
<max_columns>3</max_columns>
<application/>
</screen_item>
</screen_items>
</screen>
</screens>
</template>
<template>
<template>Template Juniper SRX RPM</template>
<name>Template Juniper SRX RPM</name>
<description/>
<groups>
<group>
<name>Juniper</name>
</group>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>Juniper RPM Discovery</name>
<type>10</type>
<snmp_community/>
<snmp_oid/>
<key>discovery_juniper_rpm.py[{HOST.CONN},{$SNMP_COMMUNITY}]</key>
<delay>5m</delay>
<status>0</status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype>0</evaltype>
<formula/>
<conditions/>
</filter>
<lifetime>30d</lifetime>
<description>Discover all RPM (Real time performance monitoring) tests that is being performed on a Juniper Network Device&#13;
the scripts returns 3 macroses:&#13;
{#RPMUUID} = &quot;3.73.83.80.49.6.84.69.83.84.49&quot; - a part of OID uniq for an RPM&#13;
{#RPMOWNER} = &quot;ISP1&quot; - RPM Owner name&#13;
{#RPMTEST} = &quot;Test1&quot; - RPM Probe name</description>
<item_prototypes>
<item_prototype>
<name>RTT {#RPMOWNER} test {#RPMTEST}</name>
<type>4</type>
<snmp_community>{$SNMP_COMMUNITY}</snmp_community>
<snmp_oid>1.3.6.1.4.1.2636.3.50.1.1.1.2.{#RPMUUID}.1</snmp_oid>
<key>delay[&quot;{#RPMUUID}&quot;]</key>
<delay>30s</delay>
<history>1w</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>ms</units>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>1</type>
<params>0.001</params>
</step>
</preprocessing>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
<item_prototype>
<name>Jitter {#RPMOWNER} test {#RPMTEST}</name>
<type>4</type>
<snmp_community>{$SNMP_COMMUNITY}</snmp_community>
<snmp_oid>1.3.6.1.4.1.2636.3.50.1.1.1.2.{#RPMUUID}.2</snmp_oid>
<key>jitter[&quot;{#RPMUUID}&quot;]</key>
<delay>30s</delay>
<history>1w</history>
<trends>365d</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units>ms</units>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>1</type>
<params>0.001</params>
</step>
</preprocessing>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
<item_prototype>
<name>PacketLoss {#RPMOWNER} test {#RPMTEST}</name>
<type>4</type>
<snmp_community>{$SNMP_COMMUNITY}</snmp_community>
<snmp_oid>1.3.6.1.4.1.2636.3.50.1.2.1.4.{#RPMUUID}.2</snmp_oid>
<key>PacketLoss[&quot;{#RPMUUID}&quot;]</key>
<delay>30s</delay>
<history>1w</history>
<trends>365d</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units>%</units>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>RPM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Template Juniper SRX RPM:PacketLoss[&quot;{#RPMUUID}&quot;].last()}&gt;2</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>{#RPMOWNER} PacketLoss: {ITEM.LASTVALUE}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>4</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes>
<graph_prototype>
<name>{#RPMOWNER}:{#RPMTEST} GRAPH</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>0</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>1A7C11</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template Juniper SRX RPM</host>
<key>delay[&quot;{#RPMUUID}&quot;]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>0</drawtype>
<color>F63100</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template Juniper SRX RPM</host>
<key>jitter[&quot;{#RPMUUID}&quot;]</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>0</drawtype>
<color>2774A4</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template Juniper SRX RPM</host>
<key>PacketLoss[&quot;{#RPMUUID}&quot;]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
</graph_prototypes>
<host_prototypes/>
<jmx_endpoint/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens>
<screen>
<name>Juniper RPM Screen</name>
<hsize>1</hsize>
<vsize>1</vsize>
<screen_items>
<screen_item>
<resourcetype>20</resourcetype>
<width>500</width>
<height>100</height>
<x>0</x>
<y>0</y>
<colspan>1</colspan>
<rowspan>1</rowspan>
<elements>0</elements>
<valign>0</valign>
<halign>0</halign>
<style>0</style>
<url/>
<dynamic>0</dynamic>
<sort_triggers>0</sort_triggers>
<resource>
<name>{#RPMOWNER}:{#RPMTEST} GRAPH</name>
<host>Template Juniper SRX RPM</host>
</resource>
<max_columns>3</max_columns>
<application/>
</screen_item>
</screen_items>
</screen>
</screens>
</template>
</templates>
</zabbix_export>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment