📜 ⬆️ ⬇️

Zabbix: LLD-monitoring of SIM-cards Yeastar TG


A few months ago I got a Yeastar TG200 GSM gateway. The equipment itself is good, which is not to say about the egg operator, who periodically puts a pig. That's why it became necessary to have up-to-date information on the status of the SIM-app and respond to dumps. The problem is only in one: in this machine, as in the whole series, there is no SNMP. But there is an API (AMI). I did not find a complete solution, so I decided to make my bike a mechanism for polling the device. On its basis, the whole monitoring of Zabbix will be built. What you need for this:


Template


The template is based on version 4.2, but it will probably work on earlier versions. The main thing is that your version supports preprocessing in LLD dependent elements.
Out of the box, data on IMSI, SMS center, operator, signal level, states and last action are monitored. If desired, it is very easy to create a prototype with the desired conversion. Also in the template there are several triggers, including the fall of the SIM interface and its replacement. It is worth mentioning that only the inserted sims are detected. It turns off in the detection filters (you never know, maybe someone needs it). Of course, the script must lie in externalscripts and have rights to execute other users.

Hardware - Yeastar TG.xml
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>4.2</version>
<date>2019-06-04T19:58:15Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Hardware - Yeastar TG</template>
<name>Hardware - Yeastar TG</name>
<description> SIM- Yeastar TG.&#13;
yeastar.sh&#13;
:&#13;
{$APIUSER} - API&#13;
{$APIPASS} - API&#13;
.</description>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>SIM</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>SIM-</name>
<type>10</type>
<snmp_community/>
<snmp_oid/>
<key>yeastarsim.sh[discovery,{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
<delay>1h</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>1</evaltype>
<formula/>
<conditions>
<condition>
<macro>{#POWER}</macro>
<value>Power on</value>
<operator>8</operator>
<formulaid>A</formulaid>
</condition>
<condition>
<macro>{#STATUS}</macro>
<value>Undetected SIM Card</value>
<operator>9</operator>
<formulaid>B</formulaid>
</condition>
</conditions>
</filter>
<lifetime>3d</lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>SIM{#NUM} - IMSI</name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.imsi[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>SIM IMSI: (.*)
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - </name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.last[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>Last event: (.*)
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - </name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.networkstatus[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>Network Status: (.*)
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - </name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.operator[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>Network Name: (.*)
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - </name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.signal[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>30d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>Signal Quality \(0,31\): (.*)
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - SMS-</name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.smscenter[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>SIM SMS Center Number: (.*)
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - </name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.state[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>State: (.*)
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - </name>
<type>18</type>
<snmp_community/>
<snmp_oid/>
<key>hardware.yeastar.sim.status[{#ID}]</key>
<delay>0</delay>
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>5</type>
<params>Status: .*, (.*), .*, .*
\1</params>
<error_handler>0</error_handler>
<error_handler_params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>SIM{#NUM} - Parsing</name>
<type>10</type>
<snmp_community/>
<snmp_oid/>
<key>yeastarsim.sh[{#ID},{HOST.CONN},{$APIUSER},{$APIPASS}]</key>
<delay>2m</delay>
<history>1h</history>
<trends>0</trends>
<status>0</status>
<value_type>4</value_type>
<allowed_hosts/>
<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>SIM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<application_prototypes/>
<master_item/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Hardware - Yeastar TG:hardware.yeastar.sim.imsi[{#ID}].diff()}=1 and {Hardware - Yeastar TG:hardware.yeastar.sim.status[{#ID}].regexp(Undetected SIM Card)}=0</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name> SIM{#NUM} {HOST.NAME}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>2</priority>
<description/>
<type>0</type>
<manual_close>1</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
<trigger_prototype>
<expression>{Hardware - Yeastar TG:hardware.yeastar.sim.status[{#ID}].regexp(Undetected SIM Card)}=1</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name> SIM{#NUM} {HOST.NAME}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<manual_close>1</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
<trigger_prototype>
<expression>{Hardware - Yeastar TG:hardware.yeastar.sim.state[{#ID}].regexp(SIM PIN REQ,#2)}=1</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name> PIN SIM{#NUM} {HOST.NAME}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
<trigger_prototype>
<expression>{Hardware - Yeastar TG:hardware.yeastar.sim.smscenter[{#ID}].regexp(.*,#2)}=0</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name> SMS- SIM{#NUM} {HOST.NAME}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>2</priority>
<description/>
<type>0</type>
<manual_close>1</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
<trigger_prototype>
<expression>{Hardware - Yeastar TG:hardware.yeastar.sim.signal[{#ID}].avg(#3)}&lt;9</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name> SIM{#NUM} {HOST.NAME}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>1</priority>
<description/>
<type>0</type>
<manual_close>1</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
<trigger_prototype>
<expression>{Hardware - Yeastar TG:hardware.yeastar.sim.status[{#ID}].regexp(Down,#2)}=1</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name> SIM{#NUM} {HOST.NAME}</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> SIM{#NUM}</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</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>2</drawtype>
<color>1A7C11</color>
<yaxisside>0</yaxisside>
<calc_fnc>7</calc_fnc>
<type>0</type>
<item>
<host>Hardware - Yeastar TG</host>
<key>hardware.yeastar.sim.signal[{#ID}]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
</graph_prototypes>
<host_prototypes/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<lld_macro_paths/>
<preprocessing/>
<master_item/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens/>
<tags/>
</template>
</templates>
</zabbix_export>


Script


yeastarsim.sh
#!/bin/bash
# 2019/05/24 AcidVenom v1.0
# LLD- SIM- API Yeastar Zabbix
# : $discovery_2_3_etc $IP $APIUSER $APIPASS
# SIM-
# - discovery
IFS=$'\n'
JSON="{\"data\":["
SEP=""
if [[ $1 = "discovery" ]]
then
get=`echo -e "Action: Login\nUsername: $3\nSecret: $4\n\nAction: smscommand\nCommand: gsm show spans\n\nAction: Logoff\n\n" | nc $2 5038 | grep "span [0-9]*:"`
for pool in $get
do
id=`echo $pool | sed "s/.* span //g" | sed "s/:.*//g"`
num=$(($id-1))
power=`echo $pool | grep "span [0-9]*:" | sed "s/.*: //g" | sed "s/,.*//g"`
status=`echo $pool | grep "span [0-9]*:" | sed "s/.*: //g" | sed "s/^.*, \(.*\), .*, .*/\1/g"`
JSON=$JSON"$SEP{\"{#ID}\":\"$id\", \"{#NUM}\":\"$num\", \"{#POWER}\":\"$power\", \"{#STATUS}\":\"$status\"}"
SEP=", "
done
JSON=$JSON"]}"
echo $JSON
# SIM-
# - discovery ("2", "3" ..)
else
echo -e "Action: Login\nUsername: $3\nSecret: $4\n\nAction: smscommand\nCommand: gsm show span $1\n\nAction: Logoff\n\n" | nc $2 5038
fi
view raw yeastarsim.sh hosted with ❤ by GitHub


The script receives the following parameters:
$ 1 - discovery or the number of the span that discovery will detect
$ 2 - {HOST.CONN} - node address
$ 3 - {$ APIUSER} - API username
$ 4 - {$ APIPASS} - API password
')
When requesting discovery, the script gives JSON with all SIM-cards, their status, spans and numbers (one less for readability). When a span is requested, complete information is uncensored for parsing.

Therefore, in order to work correctly, you need to specify in each node to which this template is attached, the {$ APIUSER} and {$ APIPASS} macros. If such macros already exist, simply rename them in the template, say, to {$ TGAPIUSER} and {$ TGAPIPASS}. If you use the same passwords for the API on all gateways, use global macros. Again, the API on the gateway side must be activated, the credentials must be correct.

Bonus


As a bonus I will leave the SMS sending script from Zabbix. The script must be put in the alertscripts folder and granted to execute by other users.

yeastarsms.sh
#!/bin/bash
# AcidVenom 2019/05/20 v1.0
# SMS API Yeastar
# : $IP $APIUSER $APIPASS $SPAN $PHONE $MESSAGE
span=$(($4+1))
# SMS
echo -e "Action: Login\nUsername: $2\nSecret: $3\n\nAction: smscommand\nCommand: gsm send sms $span $5 \"$6\"\n\nAction: Logoff\n\n" | nc $1 5038
view raw yeastarsms.sh hosted with ❤ by GitHub


Then go to AdministrationAlert MethodsCreate Alert Method and select a Script . The name of the script must match the name of the file (in my case, yeastarsms.sh). The script itself accepts the following variables (parameters):

$ 1 - ip or dns gateway
$ 2 - API username
$ 3 - API password
$ 4 - SIM port as it is (for example 1)
$ 5 recipient (I use {ALERT.SENDTO})
$ 6 - message (I use {ALERT.SUBJECT})
When changing the order of the parameters, the script will not work .

I would be happy to suggestions and comments.

PS: Improved the replacement and withdrawal triggers SIM. Download the template.

Source: https://habr.com/ru/post/454702/


All Articles