├── .codeclimate.yml ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── README.txt ├── __init__.py ├── doc ├── check_jenkins_api │ └── README.md ├── check_local_cpu_temp │ └── README.md ├── check_meinberg_ntp │ ├── README.md │ └── example_commands_check_meinberg_ntp.cfg ├── check_moxa_6000 │ ├── README.md │ └── example_commands_check_moxa_6000.cfg ├── check_snmp_apc_ups │ ├── README.md │ └── example_commands_check_snmp_apc_ups.cfg ├── check_snmp_eaton_ups │ ├── README.md │ └── examlpe_commands_check_snmp_eaton_ups.cfg ├── check_snmp_eps_plus │ └── README.md ├── check_snmp_fortinet │ ├── README.md │ └── example_commands_check_snmp_fortinet.cfg ├── check_snmp_idrac │ └── README.md ├── check_snmp_ilo4 │ ├── README.md │ └── example_commands_check_snmp_ilo4.cfg ├── check_snmp_janitza │ └── README.md ├── check_snmp_large_storage │ ├── README.md │ └── example_commands_check_snmp_large_storage.cfg ├── check_snmp_lband │ ├── README.md │ └── example_commands_check_snmp_lband.cfg ├── check_snmp_port │ ├── README.md │ └── example_commands_check_snmp_port.cfg ├── check_snmp_procurve │ ├── README.md │ └── example_commands_check_snmp_procurve.cfg ├── check_snmp_raritan │ ├── README.md │ └── example_commands_check_snmp_raritan.cfg ├── check_snmp_service │ ├── README.md │ └── example_commands_check_snmp_service.cfg ├── check_snmp_teledyne │ ├── README.md │ └── example_commands_check_snmp_teledyne.cfg ├── check_snmp_time2 │ ├── README.md │ └── example_commands_check_snmp_time2.cfg └── check_snmp_ubiquiti │ └── README.md ├── health_monitoring_plugins ├── __init__.py ├── cambium.py ├── check_jenkins_api │ └── check_jenkins_api.py ├── check_local_cpu_temperature │ └── check_local_cpu_temperature.py ├── check_meinberg_ntp │ └── check_meinberg_ntp.py ├── check_microwavemodem │ └── check_microwavemodem.py ├── check_moxa_6000 │ └── check_moxa_6000.py ├── check_newtecmodem │ └── check_newtecmodem.py ├── check_snmp_apc_ups │ └── check_snmp_apc_ups.py ├── check_snmp_cambium_ptp700 │ └── check_snmp_cambium_ptp700.py ├── check_snmp_eaton_ups │ └── check_snmp_eaton_ups.py ├── check_snmp_eps_plus │ └── check_snmp_eps_plus.py ├── check_snmp_fortinet │ └── check_snmp_fortinet.py ├── check_snmp_idrac │ └── check_snmp_idrac.py ├── check_snmp_ilo4 │ └── check_snmp_ilo4.py ├── check_snmp_inradios_csm │ └── check_snmp_inradios_csm.py ├── check_snmp_janitza │ └── check_snmp_janitza.py ├── check_snmp_large_storage │ └── check_snmp_large_storage.py ├── check_snmp_lband │ └── check_snmp_lband.py ├── check_snmp_port │ └── check_snmp_port.py ├── check_snmp_procurve │ └── check_snmp_procurve.py ├── check_snmp_raritan │ └── check_snmp_raritan.py ├── check_snmp_s650 │ └── check_snmp_s650.py ├── check_snmp_service │ └── check_snmp_service.py ├── check_snmp_teledyne │ └── check_snmp_teledyne.py ├── check_snmp_time2 │ └── check_snmp_time2.py ├── check_snmp_trusted_filter │ └── check_snmp_trusted_filter.py ├── check_snmp_ubiquiti │ └── check_snmp_ubiquiti.py ├── eaton.py ├── eps_plus.py ├── idrac.py ├── ilo.py ├── inradios_csm.py ├── ipport.py ├── meinberg.py ├── microwavemodem.py ├── newtecmodem.py ├── plugin_rules.md ├── procurve.py ├── raritan.py ├── snmpSessionBaseClass.py ├── storage.py ├── timesource.py ├── trustedfilter.py └── windowsservice.py ├── icingaexchange.yml ├── run_unittest.sh ├── setup.py └── test ├── SITLineIP-MIB.txt ├── SNMPv2-SMI ├── SNMPv2-TC ├── context.py ├── snmpCSM_Server.mib ├── test_check_meinberg_ntp.py ├── test_check_microwavemodem.py ├── test_check_moxa_6000.py ├── test_check_newtecmodem.py ├── test_check_snmp_apc_ups.py ├── test_check_snmp_cambium_ptp700.py ├── test_check_snmp_eaton_ups.py ├── test_check_snmp_eps_plus.py ├── test_check_snmp_fortinet.py ├── test_check_snmp_idrac.py ├── test_check_snmp_ilo4.py ├── test_check_snmp_inradios_csm.py ├── test_check_snmp_janitza.py ├── test_check_snmp_large_storage.py ├── test_check_snmp_lband.py ├── test_check_snmp_port.py ├── test_check_snmp_procurve.py ├── test_check_snmp_raritan.py ├── test_check_snmp_s650.py ├── test_check_snmp_service.py ├── test_check_snmp_teledyne.py ├── test_check_snmp_time2.py ├── test_check_snmp_trusted_filter.py ├── test_check_snmp_ubiquiti.py ├── test_snmpSessionBaseClass.py ├── test_util.py └── testagent ├── __init__.py ├── eventloop.py ├── masteragent.py ├── netsnmpagent.py ├── netsnmpapi.py └── snmp_fd.py /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | Python: true 2 | 3 | rubocop: 4 | enabled: true 5 | #checks: 6 | # Rubocop/Metrics/ClassLength: 7 | # enabled: false 8 | golint: 9 | enabled: true 10 | eslint: 11 | enabled: true 12 | csslint: 13 | enabled: true 14 | duplication: 15 | enabled: true 16 | config: 17 | languages: 18 | - python 19 | # ... CONFIG CONTENT ... 20 | exclude_fingerprints: 21 | - b5024d779ba0982e139af401d41c0d62 22 | - 890832ed3de4dd0e3bf354ad42f6a544 23 | # ... CONFIG CONTENT ... -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled python modules. 2 | *.pyc 3 | 4 | # bak files 5 | *.bak 6 | 7 | # sencere files 8 | *sencere* 9 | 10 | # Setuptools distribution folder. 11 | /dist/ 12 | 13 | # Build folder 14 | /build/ 15 | 16 | # Python egg metadata, regenerated from source files by setuptools. 17 | /*.egg-info 18 | 19 | # Index files and folders 20 | *.index 21 | 22 | # Cache folder 23 | .cache/ -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include run_unittest.sh 3 | recursive-include doc README.md -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Please check the README.md for more details 2 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsmuc/health_monitoring_plugins/17d274541e5f165fd82c2b32f1b21d8581352933/__init__.py -------------------------------------------------------------------------------- /doc/check_jenkins_api/README.md: -------------------------------------------------------------------------------- 1 | ## check_jenkins_api.py: 2 | --- 3 | 4 | Check the status the Jenkins job queue. 5 | 6 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 7 | 8 | The plugin checks several Jenkins parameters. 9 | 10 | The plugin is just a quick and dirty solution to monitor our Jenkins. For the plugin there is no automatic test or a quality control. 11 | 12 | 13 | ### Example: 14 | 15 | #### Job queue 16 | 17 | The plugin checks the age of all Jobs in the Jenkins job queue. IF the age of a single job is older than X hours, a critical status is shown. 18 | We want to avoid that the Jenkins job queue is growing and growing and we don't get notified. 19 | 20 | 21 | ```./check_jenkins.py -H 'myjenkins.domain.net/MYJENKINS' -U 'user' -P 'password' -A 12.0``` 22 | ``` 23 | ``` 24 | => 25 | Critical - JENKINS JOB WAITING FOR 14.0 hours - CHECK INSTANCES 26 | ``` 27 | 28 | #### Shutdown mode 29 | 30 | The plugin checks if Jenkins is in shutdown mode: 31 | 32 | ```./check_jenkins.py -H 'myjenkins.domain.net/MYJENKINS' -U 'user' -P 'password' -S 33 | ``` 34 | ``` 35 | => 36 | Warning - myjenkins.domain.net/MYJENKINS. JENKINS IS IN SHUTDOWN MODE 37 | ``` 38 | 39 | #### Executor status 40 | 41 | The plugin check if an executor is temporarily offline (warning) of offline (critical) 42 | 43 | 44 | ```./check_jenkins.py -H 'myjenkins.domain.net/MYJENKINS' -U 'user' -P 'password' -D 45 | ``` 46 | ``` 47 | => 48 | Warning - myjenkins.domain.net/MYJENKINS. Jenkins executor temporarily offline. 49 | ``` 50 | 51 | ### Options 52 | ``` 53 | -h, --help show this help message and exit 54 | 55 | -p PORT the port the Jenkins webserver (default: 80) 56 | 57 | -H HOST the IP address or hostname of the Jenkins 58 | 59 | -U USER the user for the basic authentication) 60 | 61 | -P PASSWORD the password for the basic authentication) 62 | 63 | -A AGE the maximum age of a Jenkins job in hours 64 | 65 | 66 | ``` -------------------------------------------------------------------------------- /doc/check_local_cpu_temp/README.md: -------------------------------------------------------------------------------- 1 | ## check_local_cpu_temp.py: 2 | --- 3 | 4 | Check the local CPU temperature without the usage of "lm-sensors" 5 | 6 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 7 | 8 | The plugins is able to check the CPU temperature without dependencies to lm-sensors. The check-lm-sensors plugin stopped working for us with the migration to Debian 9. 9 | 10 | 11 | ### Example: 12 | 13 | #### CPU Temperature 14 | 15 | Reading the temperature from /sys/class/thermal/thermal_zone0/temp 16 | 17 | 18 | ```./check_local_cpu_temp.py -C temp1 --threshold metric=temp,warning=:15,critical=:25``` 19 | ``` 20 | ``` 21 | => 22 | Critical - CPU temperature: 26.8 C. Critical on temp | 'cpu'=26.8;:50;:25;; 23 | ``` 24 | 25 | #### Core temperature 26 | 27 | Reading the temperature from /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp2_input 28 | 29 | For Core 1: -C "Core 0" 30 | For Core 3: -C "Core 2" 31 | 32 | ```./check_local_cpu_temp.py -C "Core 0" --threshold metric=temp,warning=:50,critical=:95``` 33 | ``` 34 | ``` 35 | => 36 | OK - Core 0 temperature: 42.0 C | 'temp'=42.0;:50;:95;; 37 | ``` 38 | 39 | 40 | ### Options 41 | ``` 42 | -h, --help show this help message and exit 43 | 44 | -C check the component (temp1, "Core 0", "Core 1", "Core x") 45 | 46 | ``` -------------------------------------------------------------------------------- /doc/check_meinberg_ntp/README.md: -------------------------------------------------------------------------------- 1 | ## check_meinberg_ntp.py: 2 | --- 3 | 4 | Check the Meinberg NTP server LANTIME M300. 5 | 6 | The plugin checks the current ntp and gps state, shows the current gps position and checks the good satellites. 7 | Tested with firmware version 5.30 and 6.18 (NG). 8 | 9 | Checked values: 10 | * GPS status 11 | * NTP status 12 | * Amount of satellites 13 | * Shows the current GPS position 14 | 15 | ### Example: 16 | 17 | #### Without threshold: 18 | 19 | ./check_meinberg_ntp.py -H 172.29.1.118 20 | 21 | => 22 | 23 | OK - GPS Position: 48.1275 11.6126 623m. Good satellites: 10 | 'satellites'=10;;;; 24 | 25 | #### With threshold: 26 | 27 | ./check_meinberg_ntp.py -H 172.29.1.118 --threshold metric=satellites,warning=8:,critical=2: 28 | 29 | => 30 | 31 | OK - GPS Position: 48.1275 11.6126 623m. Good satellites: 9 | 'satellites'=9;8:;2:;; 32 | 33 | or 34 | 35 | ./check_meinberg_ntp.py -H 172.29.1.118 --threshold metric=satellites,warning=15:,critical=11: 36 | 37 | => 38 | 39 | Critical - GPS Position: 48.1275 11.6126 623m. Good satellites: 10. Critical on satellites | 'satellites'=10;15:;11:;; 40 | 41 | #### Check a Meinberg timeserver M300 with firmware version 6 or newer: 42 | 43 | ./check_meinberg_ntp.py -H 172.29.1.118 -m NG 44 | 45 | ## Parameters 46 | ``` 47 | - -H HOSTNAME Hostname or ip address 48 | - --version=VERSION SNMP version (default: 2) 49 | - --community=COMMUNITY SNMP community (default: public) 50 | - -m MIB Version of the MIB (NG = MBG-LANTIME-NG-MIB.mib) 51 | ``` 52 | -------------------------------------------------------------------------------- /doc/check_meinberg_ntp/example_commands_check_meinberg_ntp.cfg: -------------------------------------------------------------------------------- 1 | 2 | # $ARG1$: the snmp community 3 | # $ARG2$: the version of the MIB that should be used (v1 or NG) depending on the firmware version of the device 4 | # $ARG3$: The warning threshold for the satellites metric 5 | # $ARG5$: The critical threshold for the satellites metric 6 | 7 | define command { 8 | command_name check_meinberg_ntp 9 | command_line /usr/local/bin/check_meinberg_ntp.py -H $HOSTADDRESS$ --community=$ARG1$ -m $ARG2$ --threshold metric=satellites,warning=$ARG3$,critical=$ARG4$ 10 | } 11 | 12 | -------------------------------------------------------------------------------- /doc/check_moxa_6000/README.md: -------------------------------------------------------------------------------- 1 | ## check_moxa_6000.py: 2 | --- 3 | 4 | Check the status of a Moxa NPORT 6000 RS232 to LAN converter. 5 | 6 | You can check each port for the CTS, DSR, DTR and Error count. 7 | 8 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 9 | 10 | 11 | ### Example: 12 | 13 | #### Check Port 1: 14 | ```./check_moxa_6000.py -H 192.168.2.12 -p 1``` 15 | 16 | 17 | ## Options 18 | 19 | - -h, --help show this help message and exit 20 | 21 | - -H HOSTNAME, --hostname=HOSTNAME 22 | Host name or IP Adress of hte MOXA device. 23 | - -C COMMUNITY, --community=COMMUNITY 24 | SNMP community of the SNMP service on target host. 25 | - -V SNMPVERSION, --snmpversion=SNMPVERSION 26 | SNMP version. 27 | - -p PORT, --port=PORT Moxa RS232 port number. 28 | - -t TYPE, --type=TYPE Available check types: CTS, DSR, DTR, ErrorCount. 29 | Example: -t CTS_ErrorCount. 30 | CTS (Clear To Send): DCE (Data Communication 31 | Equipment) is ready to accept data from the DTE (Data 32 | Terminal Equipment). 33 | DSR (Data Set Ready): DCE (Data Communication 34 | Equipment) is ready to receive commands or data. 35 | DTR (Data Terminal Ready): DTE (Data Terminal 36 | Equipment) is ready to receive, initiate, or continue 37 | a call. 38 | ErrorCount = Show error counts of Frame, Break, 39 | Overrun and Parity. 40 | - -c CRITICAL, --critical=CRITICAL 41 | Return CRITICAL if any ErrorCount >= this parameter. 42 | - -w WARNING, --warning=WARNING 43 | Return WARNING if any ErrorCount >= this parameter. 44 | 45 | -------------------------------------------------------------------------------- /doc/check_moxa_6000/example_commands_check_moxa_6000.cfg: -------------------------------------------------------------------------------- 1 | 2 | # $ARG1$: the snmp community 3 | # $ARG2$: the check type 4 | # $ARG3$: the port that should be checked 5 | 6 | define command { 7 | command_name check_moxa_6000 8 | command_line /usr/local/bin/check_moxa_6000.py -H $HOSTADDRESS$ -C $ARG1$ -t $ARG2$ -p $ARG3$ 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc/check_snmp_apc_ups/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_apc_ups.py 2 | --- 3 | 4 | Check state of a Schneider APC UPS: 5 | The plugin checks various characteristics of an APC UPS. It gets an SNMP value according to 6 | the defined check type and compares the returned value against the set thresholds. 7 | 8 | Checkable values: 9 | * input voltage, frequency 10 | * output voltage, current, power, load 11 | * remaining runtime 12 | * remaining battery capacity 13 | * battery state 14 | * environmental temperature 15 | 16 | Tested device: None. Just simulated with a snmpwalk of a "Smart-UPS RT 3000 XL" 17 | 18 | ### Example: 19 | 20 | #### Check Input Voltage 21 | 22 | ./check_snmp_apc_ups.py -H 172.29.1.2 -t INPUT_VOLTAGE -w 228:232 -c 226:234 23 | 24 | => 25 | 26 | Critical - Input Voltage is 114 VAC | 'INPUT_VOLTAGE'=114VAC;228:232;226:234;; 27 | 28 | 29 | ## Parameters 30 | ``` 31 | Options: 32 | -h, --help show this help message and exit 33 | -H HOSTNAME Hostname or ip address 34 | -C COMMUNITY, --community=COMMUNITY 35 | SNMP community of the SNMP service on target host. 36 | -V VERSION, --snmpversion=VERSION 37 | SNMP version. (1 or 2) 38 | -t CHECKTYPE The value you want to monitor 39 | One out of BASIC_BATTERY_STATUS, TIME_ON_BATTERY, 40 | BATTERY_CAPACITY, INTERNAL_TEMPERATURE, 41 | RUNTIME_REMAINING, BATTERY_REPLACE_INDICATOR, 42 | INPUT_VOLTAGE, INPUT_FREQUENCY, OUTPUT_VOLTAGE, 43 | OUTPUT_LOAD, OUTPUT_CURRENT, OUTPUT_POWER, 44 | LAST_TEST_RESULT, ENVIRONMENT_TEMPERATURE 45 | -w WARNING_THRESHOLDS Thresholds in icinga threshold range syntax 46 | -c CRITICAL_THRESHOLDS Thresholds in icinga threshold syntax 47 | ``` -------------------------------------------------------------------------------- /doc/check_snmp_apc_ups/example_commands_check_snmp_apc_ups.cfg: -------------------------------------------------------------------------------- 1 | # RACON-Name: Service APC UPS 2 | # Check various snmp values of a Schneider APC UPS 3 | # 4 | # ARG1: snmp community 5 | # ARG2: check type 6 | # Defines which value shall be evaluated/checked. 7 | # See the check plugin help for available check types. 8 | # ARG3: warning threshold 9 | # Will be ignored for check types without thresholds/metrics 10 | # ARG4: critical threshold 11 | # Will be ignored for check types without thresholds/metrics 12 | 13 | 14 | define command { 15 | command_name check_snmp_apc_ups 16 | command_line check_snmp_apc_ups.py -H $HOSTADDRESS$ -C $ARG1$ -t $ARG2$ -w $ARG3$ -c $ARG4$ 17 | } 18 | -------------------------------------------------------------------------------- /doc/check_snmp_eaton_ups/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_eaton_ups.py: 2 | 3 | --- 4 | 5 | Check state of an Eaton UPS. 6 | The plugin checks various characteristics of an Eaton UPS. It gets a SNMP value according to 7 | the defined check type and compares the returned value against the set thresholds. 8 | 9 | Checkable values: 10 | 11 | * input voltage, frequency 12 | * output voltage, current, power, load 13 | * time on battery 14 | * remaining runtime 15 | * remaining battery capacity 16 | * alarms 17 | * ~~battery test summary and details (not available for Eaton 9SX)~~ 18 | * ~~battery state (low, replacement, fault) (not available for Eaton 9SX)~~ 19 | * internal and environmental temperature 20 | 21 | ### Example: 22 | 23 | #### Check remaining battery capacity 24 | 25 | ./check_snmp_eaton_ups.py -H 172.29.1.118 -t battery_capacity --threshold metric=battery_capacity,warning=20:,critical=10: 26 | 27 | => 28 | 29 | OK - Remaining Battery Capacity 100 % | 'battery_capacity'=100%;20:;10:;; 30 | 31 | #### Check UPS alarms 32 | 33 | ``` 34 | ./check_snmp_eaton_ups.py -H 172.29.1.118 -t alarms 35 | ``` 36 | 37 | => 38 | 39 | OK - 0 active alarms 40 | 41 | ## Parameters 42 | 43 | ``` 44 | Options: 45 | -h, --help show this help message and exit 46 | -H HOSTNAME Hostname or ip address 47 | -C COMMUNITY, --community=COMMUNITY 48 | SNMP community of the SNMP service on target host. 49 | -V VERSION, --snmpversion=VERSION 50 | SNMP version. (1, 2 or 3) 51 | -t TYPE, --type=TYPE Check type to execute. Available types are: 52 | on_battery, remaining_battery_time, input_frequency, 53 | input_voltage, output_voltage, output_current, 54 | output_power, output_load, alarms, battery_capacity, 55 | environment_temperature, 56 | external_environment_temperature 57 | -U SECNAME, --securityname=SECNAME 58 | SNMPv3: security name (e.g. bert) 59 | -L SECLEVEL, --securitylevel=SECLEVEL 60 | SNMPv3: security level (noAuthNoPriv, authNoPriv, 61 | authPriv) 62 | -a AUTHPROTO, --authprotocol=AUTHPROTO 63 | SNMPv3: authentication protocol (MD5|SHA) 64 | -A AUTHPASS, --authpass=AUTHPASS 65 | SNMPv3: authentication protocol pass phrase 66 | -x PRIVPROTO, --privproto=PRIVPROTO 67 | SNMPv3: privacy protocol (DES|AES) 68 | -X PRIVPASS, --privpass=PRIVPASS 69 | SNMPv3: privacy protocol pass phrase 70 | 71 | Generic Options: 72 | --timeout=50 Exit plugin with unknown status after x seconds 73 | --threshold=range Thresholds in standard nagios threshold format 74 | --th=range Same as --threshold 75 | --extra-opts=@file Read options from an ini file. See 76 | http://nagiosplugins.org/extra-opts 77 | -d, --debug Print debug info 78 | 79 | Display Options: 80 | -v, --verbose Print more verbose info 81 | --no-perfdata Dont show any performance data 82 | --no-longoutput Hide longoutput from the plugin output (i.e. only 83 | display first line of the output) 84 | --no-summary Hide summary from plugin output 85 | --get-metrics Print all available metrics and exit (can be combined 86 | with --verbose) 87 | --legacy Deprecated, do not use 88 | 89 | ``` 90 | -------------------------------------------------------------------------------- /doc/check_snmp_eaton_ups/examlpe_commands_check_snmp_eaton_ups.cfg: -------------------------------------------------------------------------------- 1 | # RACON-Name: Service Eaton UPS 2 | # Check various snmp values of an Eaton UPS 3 | # 4 | # ARG1: snmp community 5 | # ARG2: check type 6 | # Defines which value shall be evaluated/checked. 7 | # See the check plugin help for available check types. 8 | # ARG3: warning threshold 9 | # Will be ignored for check types without thresholds/metrics 10 | # ARG4: critical threshold 11 | # Will be ignored for check types without thresholds/metrics 12 | 13 | 14 | define command { 15 | command_name check_snmp_eaton_ups 16 | command_line check_snmp_eaton_ups.py -H $HOSTADDRESS$ -C $ARG1$ -t $ARG2$ 17 | } 18 | 19 | 20 | define command { 21 | command_name check_snmp_eaton_ups_threshold 22 | command_line check_snmp_eaton_ups.py -H $HOSTADDRESS$ -C $ARG1$ -t $ARG2$ --threshold metric=$ARG2$,warning=$ARG3$,critical=$ARG4$ 23 | } -------------------------------------------------------------------------------- /doc/check_snmp_eps_plus/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_eps_plus.py: 2 | 3 | --- 4 | 5 | Check state of an ePowerSwitch (8XM+) 6 | This plugin is able to check the analog sensors (Temperature and Humidity) and the status of the outlets 7 | 8 | ### Example: 9 | 10 | #### Check the first outlet of the master 11 | 12 | ./check_snmp_eps_plus.py -H 172.1.2.3 --device 0 --outlet 0 13 | 14 | => 15 | 16 | OK - SYS0X-EPS-M01 - SYS0X-Outlet1: On 17 | 18 | 19 | #### Check the Temperature Sensor 20 | 21 | ``` 22 | ./check_snmp_eps_plus.py -H 172.1.2.3 --sensor T1 --threshold metric="temperature sensor (in deg. c)",warning=:20,critical=:30 23 | ``` 24 | 25 | => 26 | 27 | Warning - TEMPERATURE SENSOR: 23 deg. C. Warning on temperature sensor (in deg. c) | 'temperature sensor (in deg. c)'=23;:20;:30;; 28 | 29 | ## Parameters 30 | 31 | ``` 32 | Options: 33 | -h, --help show this help message and exit 34 | -H HOSTNAME, --hostname=HOSTNAME 35 | Hostname or ip address 36 | -C COMMUNITY, --community=COMMUNITY 37 | SNMP community of the SNMP service on target host. 38 | -V SNMPVERSION, --snmpversion=SNMPVERSION 39 | SNMP version. (1 or 2) 40 | --retries=RETRIES Number of SNMP retries. 41 | -U SECNAME, --securityname=SECNAME 42 | SNMPv3: security name (e.g. bert) 43 | -L SECLEVEL, --securitylevel=SECLEVEL 44 | SNMPv3: security level (noAuthNoPriv, authNoPriv, 45 | authPriv) 46 | -a AUTHPROTO, --authprotocol=AUTHPROTO 47 | SNMPv3: authentication protocol (MD5|SHA) 48 | -A AUTHPASS, --authpass=AUTHPASS 49 | SNMPv3: authentication protocol pass phrase 50 | -x PRIVPROTO, --privproto=PRIVPROTO 51 | SNMPv3: privacy protocol (DES|AES) 52 | -X PRIVPASS, --privpass=PRIVPASS 53 | SNMPv3: privacy protocol pass phrase 54 | --device=DEVICE Select the device whose outlet shall be monitored (0 = 55 | master, 1 = first slave, 2 = second slave) 56 | --expected=EXPECTED Define if On or Off shall be the OK sate (On, Off) 57 | --outlet=OUTLET Select the outlet which shall be monitored (0 = first 58 | outlet) 59 | --sensor=SENSOR Select the sensor which shall be monitored (T1, T2, 60 | Tx, H1, H2, Hx) 61 | 62 | Generic Options: 63 | --timeout=50 Exit plugin with unknown status after x seconds 64 | --threshold=range Thresholds in standard nagios threshold format 65 | --th=range Same as --threshold 66 | --extra-opts=@file Read options from an ini file. See 67 | http://nagiosplugins.org/extra-opts 68 | -d, --debug Print debug info 69 | 70 | Display Options: 71 | -v, --verbose Print more verbose info 72 | --no-perfdata Dont show any performance data 73 | --no-longoutput Hide longoutput from the plugin output (i.e. only 74 | display first line of the output) 75 | --no-summary Hide summary from plugin output 76 | --get-metrics Print all available metrics and exit (can be combined 77 | with --verbose) 78 | --legacy Deprecated, do not us 79 | 80 | ``` 81 | -------------------------------------------------------------------------------- /doc/check_snmp_fortinet/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_fortinet.py: 2 | --- 3 | 4 | Check the status a fortinet wificontroller. 5 | 6 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 7 | 8 | The plugin can check the ressources of the controller (hard drive usage, cpu usage and memory usage). For the ressources there is a definied limit of 90%. 9 | The second option is to check the status of the controller (operational state, alarm state and availability state). 10 | The third option is to check ALL connected access points (operational state, alarm state and availability state). Only failed access points will be shown in the summary. In the long output all connected access points are shown. 11 | 12 | 13 | ### Example: 14 | 15 | #### Check the connected accesspoints: 16 | ```./check_snmp_fortinet.py -H 172.29.10.110 --type accesspoints``` 17 | ``` 18 | ``` 19 | => 20 | Critical - Access Points Status. ApTest1 Operational State: disabled. ApTest1 Availability State: not installed 21 | 22 | AP-1 - Operational: enabled - Availabilty: online - Alarm: no alarm 23 | ApTest1 - Operational: disabled - Availabilty: not installed - Alarm: no alarm 24 | ``` 25 | 26 | #### Check the ressources of the controller: 27 | 28 | ```./check_snmp_fortinet.py -H 172.29.10.110 --type ressources``` 29 | ``` 30 | => 31 | OK - Controller Status | 'CPU'=1%%;0:90;0:90;; 'Memory'=9%%;0:90;0:90;; 'Filesystem'=6%%;0:90;0:90;; 32 | 33 | Controller Ressources - CPU: 1% 34 | Memory: 9% 35 | Filesystem: 6% 36 | ``` 37 | 38 | 39 | #### Check the controller Status: 40 | ```/check_snmp_fortinet.py -H 172.29.10.110 --type controller``` 41 | ``` 42 | => 43 | OK - Controller Status 44 | 45 | Controller Operational State: enabled 46 | Controller Availability State: online 47 | Controller Alarm State: no alarm 48 | ``` 49 | ``` 50 | ### Options 51 | ``` 52 | - -h, --help show this help message and exit 53 | - -H HOSTNAME Hostname or ip address 54 | - -C COMMUNITY, --community=COMMUNITY 55 | SNMP community of the SNMP service on target host. 56 | - -V VERSION, --snmpversion=VERSION 57 | SNMP version. (1 or 2) 58 | - -t TYPE, --type=TYPE Check type to execute. Available types are: 59 | ressources, controller, accesspoints 60 | ``` -------------------------------------------------------------------------------- /doc/check_snmp_fortinet/example_commands_check_snmp_fortinet.cfg: -------------------------------------------------------------------------------- 1 | 2 | # $ARG1$: the snmp community 3 | # $ARG2$: the type of the check (controller, ressource, accesspoint) 4 | 5 | 6 | define command { 7 | command_name check_snmp_fortinet 8 | command_line /usr/local/bin/check_snmp_fortinet.py -H $HOSTADDRESS$ --community=$ARG1$ -t $ARG3$ 9 | } 10 | 11 | -------------------------------------------------------------------------------- /doc/check_snmp_idrac/README.md: -------------------------------------------------------------------------------- 1 | # check_snmp_idrac.py 2 | 3 | This plugin checks the health of Dell iDRAC. 4 | 5 | The following components/statuses are checked: 6 | 7 | - global system status 8 | - system LCD status 9 | - global storage status 10 | - system power status 11 | - power unit and its redundancy 12 | - chassis intrusion sensor 13 | - cooling unit 14 | - temperature probes 15 | 16 | The plugin requires [pynag] 17 | 18 | ## Options for check_snmp_idrac.py 19 | ``` 20 | -h, --help show this help message and exit 21 | -H HOSTNAME, --hostname=HOSTNAME 22 | Hostname or ip address 23 | -C COMMUNITY, --community=COMMUNITY 24 | SNMP community of the SNMP service on target host. 25 | -V SNMPVERSION, --snmpversion=SNMPVERSION 26 | SNMP version. (1 or 2) 27 | --retries=RETRIES Number of SNMP retries. 28 | --snmptimeout=SNMPTIMEOUT 29 | The timeout for one snmp get (Default: 5 seconds) 30 | -U SECNAME, --securityname=SECNAME 31 | SNMPv3: security name (e.g. bert) 32 | -L SECLEVEL, --securitylevel=SECLEVEL 33 | SNMPv3: security level (noAuthNoPriv, authNoPriv, 34 | authPriv) 35 | -a AUTHPROTO, --authprotocol=AUTHPROTO 36 | SNMPv3: authentication protocol (MD5|SHA) 37 | -A AUTHPASS, --authpass=AUTHPASS 38 | SNMPv3: authentication protocol pass phrase 39 | -x PRIVPROTO, --privproto=PRIVPROTO 40 | SNMPv3: privacy protocol (DES|AES) 41 | -X PRIVPASS, --privpass=PRIVPASS 42 | SNMPv3: privacy protocol pass phrase 43 | --no-system Do not check the global system status 44 | --no-power Do not check the power status 45 | --no-storage Do not check the storage status 46 | --no-disks Do not check the disks 47 | --no-predictive Do not check the predictive status of the disks 48 | --no-lcd Do not check the lcd status 49 | --no-power_unit Do not check the power unit 50 | --no-redundancy Do not check the power unit redundancy 51 | --no-intrusion Do not check the intrusion sensor 52 | --no-cooling Do not check the cooling unit 53 | --no-temperature Do not check the temperature 54 | 55 | 56 | ``` 57 | 58 | #### Defaults 59 | ``` 60 | -C, --community "public" 61 | -V, --snmpversion 2 62 | ``` 63 | 64 | ## Example 65 | 66 | ``` 67 | ./check_snmp_idrac.py -H 192.168.2.1 68 | ``` 69 | 70 | Output should look like this: 71 | ``` 72 | OK - User assigned name: Main System Chassis - Typ: PowerEdge R420xr - Service tag: 1AB2345 73 | Global System status: ok 74 | 75 | System LCD status: ok 76 | 77 | Global Storage status: ok 78 | 79 | System Power status: on 80 | 81 | Power unit "System Board PS" status: ok. Redundancy: full 82 | 83 | Chassis intrusion sensor "System Board Intrusion" is ok 84 | 85 | Cooling unit "System Board Fan" status: ok 86 | 87 | Temperature probe at "System Board Inlet" is ok 88 | ``` 89 | 90 | ## SNMPv3 Example: 91 | 92 | ``` 93 | ./check_snmp_idrac/check_snmp_idrac.py -H 172.29.12.130 -V 3 -u snmpuser -l AuthPriv -a SHA -A snmppassword -x AES -X snmppassword 94 | ``` 95 | 96 | ## Troubleshooting: 97 | 98 | ``` 99 | Unknown - No response from device for drive (.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1.4) 100 | 101 | ```` 102 | 103 | If you receive a no response message, the idrac interface does not respond to the snmp request. 104 | Just disable the dedicated check: In this case use --no-disk option. 105 | 106 | 107 | 108 | [pynag]: 109 | -------------------------------------------------------------------------------- /doc/check_snmp_ilo4/example_commands_check_snmp_ilo4.cfg: -------------------------------------------------------------------------------- 1 | # ARG1: community 2 | # ARG2: count power supplies 3 | # ARG3: count drives 4 | # ARG4: count fans 5 | # ARG5: other command line parameters 6 | 7 | define command { 8 | command_name check_snmp_ilo4 9 | command_line /usr/local/bin/check_snmp_ilo4.py -H $HOSTADDRESS$ -C $ARG1$ --ps=$ARG2$ --drives=$ARG3$ --fan=$ARG4$ $ARG5$ 10 | } 11 | 12 | -------------------------------------------------------------------------------- /doc/check_snmp_janitza/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_janitza.py: 2 | --- 3 | 4 | Check the status of a Janitza 604 device. 5 | 6 | You can check 'uL1', 'uL2', 'uL3', 'iL1', 'iL2', 'iL3', 'iL4', 'iL5', 'iL6', 'pL1', 'pL2', 'pL3', 'qL1', 'qL2', 'qL3', 7 | 'sL1', 'sL2', 'sL3', 'cosPL1', 'cosPL2', 'cosPL3', 'p3', 'q3', 's3', 'uL1L2', 'uL2L3', 'uL3L1' 8 | 9 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 10 | 11 | 12 | ### Example: 13 | 14 | #### Get a list of all possible types 15 | ```./check_snmp_janitza.py -l``` 16 | 17 | #### Check uL1 with warning(-10:10) and critical(-20:20) metrics (pynag standard confirm): 18 | ```./check_snmp_janitza.py -H 192.168.2.12 -t uL1 --th metric=type,warning=-10:10,critical=-20:20``` 19 | 20 | #### Check uL1 without pynag metrics: 21 | ```./check_snmp_janitza.py -H 192.168.2.12 -t uL1``` 22 | 23 | 24 | ## Options 25 | 26 | - -h, --help show this help message and exit 27 | - -l, --list lists all possible request types 28 | - -H HOSTNAME, --hostname=HOSTNAME 29 | Host name or IP Adress of hte MOXA device. 30 | - -C COMMUNITY, --community=COMMUNITY 31 | SNMP community of the SNMP service on target host. 32 | - -V SNMPVERSION, --snmpversion=SNMPVERSION 33 | SNMP version. 34 | - -t TYPE, --type=TYPE type of the request 35 | - --th metric=type,warning=WARNING_MIN:WARNING_MAX,critical=CRITICAL_MIN:CRITICAL_MAX 36 | add warning and critical values pynag confirm 37 | 38 | 39 | -------------------------------------------------------------------------------- /doc/check_snmp_large_storage/README.md: -------------------------------------------------------------------------------- 1 | 2 | # check_snmp_large_storage.py: 3 | --- 4 | 5 | Check the used / free disk space of a device via SNMP (using the HOST-RESOURCES-MIB hrStorageSize). 6 | There are already scripts doing that e.g. http://nagios.manubulon.com/snmp_storage.html . But these check scripts do have problems with large storage systems. 7 | 8 | In our case we want to monitor a Microsoft Windows Server 2012 R2 with an 10 TB partition and one Server with an 25 TB partition. The problem all scripts have, that the SNMP counter hrStorageSize is a 32 Bit 9 | Integer counter. If you have a storage that is larger then 8 TB (depending on the hrStorageAllocationUnits) you will have the issue, that the conuter overruns and will return a negative integer value. 10 | 11 | This script will handle the negative integer values and will calculate the proper size. That will only work if the counter overruns once. 12 | 13 | ### Calculation example 14 | ``` 15 | hrStorageAllocationUnits => 8192 (this value is depending on your file system configuration) 16 | hrStorageSize => -1149438977 (32Bit overrun) 17 | Maximum possible integer value => (2^32 / 2) - 1 = 2147483647 18 | Real Storage Size => (1149438977 + 2147483647) * 8192 = 27008390135808 Bytes 19 | Real Storage Size in GB => 27008390135808 Bytes / 1024 / 1024 / 1024 = 25153,52 GB 20 | ``` 21 | 22 | 23 | ### Example: 24 | 25 | #### Check without threshold: 26 | 27 | ./check_snmp_large_storage.py -H 192.168.2.1 -p "E" -u TB 28 | 29 | => 30 | 31 | OK - 38.82% used (9.54TB of 24.56TB) at E:\ Label:NAS Serial Number e95e16d | 'percent used'=38.82;;;; 32 | 33 | #### Check with threshold: 34 | 35 | ./check_snmp_large_storage.py -H 192.168.2.1 -p "E" -u TB --threshold metric="percent used",warning=10..inf,critical=95..inf``` 36 | 37 | => 38 | 39 | Critical - 38.82% used (9.54TB of 24.56TB) at E:\ Label:NAS Serial Number e95e1f. Critical on percent used | 'percent used'=38.82;~:10;~:15;; 40 | 41 | #### Show all available drive names: 42 | 43 | ./check_snmp_large_storage.py -H 192.168.2.1 --scan 44 | 45 | ### Options 46 | ``` 47 | -h, --help show this help message and exit 48 | -H HOSTNAME Hostname or ip address 49 | -C COMMUNITY, --community=COMMUNITY 50 | SNMP community of the SNMP service on target host. 51 | -V VERSION, --snmpversion=VERSION 52 | SNMP version. (1 or 2) 53 | -p PARTITION, --partition=PARTITION 54 | The disk / partition you want to monitor 55 | -u TARGETUNIT, --unit=TARGETUNIT 56 | The unit you want to have (MB, GB, TB) 57 | -s, --scan Show all available storages 58 | 59 | 60 | ``` -------------------------------------------------------------------------------- /doc/check_snmp_large_storage/example_commands_check_snmp_large_storage.cfg: -------------------------------------------------------------------------------- 1 | # ARG1: community 2 | # ARG2: The partition name 3 | # ARG3: target unit 4 | # ARG4: warning threshold 5 | # ARG5: critical threshold 6 | 7 | define command { 8 | command_name check_snmp_large_storage 9 | command_line /usr/local/bin/check_snmp_large_storage.py -H $HOSTADDRESS$ --community=$ARG1$ --partition="$ARG2$" --unit=$ARG3$ --threshold metric="percent used",warning=$ARG4$,critical=$ARG5$ 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /doc/check_snmp_lband/README.md: -------------------------------------------------------------------------------- 1 | # check_snmp_lband.py 2 | --- 3 | 4 | This plugin checks the status of the CROSS TECHNOLOGIES redundancy controller 2082-141. 5 | 6 | Implemented against MIB 2082-141.mib 7 | 8 | ### Options 9 | ``` 10 | -h, --help show this help message and exit 11 | -H HOSTNAME Hostname or ip address 12 | -C COMMUNITY, --community=COMMUNITY 13 | SNMP community of the SNMP service on target host. 14 | -V VERSION, --snmpversion=VERSION 15 | SNMP version. (1 or 2) 16 | -U UNIT, --unit=UNIT Select the unit you want to monitor, if no unit is 17 | selected both units will be monitored 18 | 19 | ``` 20 | ``` 21 | 22 | ### Examples 23 | 24 | 25 | ./check_snmp_lband.py -H 172.29.1.2 -U 1 26 | 27 | => 28 | 29 | Critical - Unit status is: Alarmed 30 | 31 | -------------------------------------------------------------------------------- /doc/check_snmp_lband/example_commands_check_snmp_lband.cfg: -------------------------------------------------------------------------------- 1 | # ARG1: the SNMP community 2 | # ARG2: the Unit 3 | 4 | define command { 5 | command_name check_snmp_lband 6 | command_line /usr/bin/check_snmp_lband.py -H $HOSTADDRESS$ -C $ARG1$ -U $ARG2$ -V 1 7 | } -------------------------------------------------------------------------------- /doc/check_snmp_port/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_port.py: 2 | --- 3 | 4 | Check the status of a tcp/udp port via SNMP. For TCP ports also the status is checked (e.g listen, established). 5 | 6 | You could also use for example the check_tcp script. But check_tcp always trys to connect to the port, so we did see a lot of connects and disconncets in the logfile of our database service. And it is also not possible to check the connection status of the port. 7 | 8 | If you know snmpnetstat, then you know how the plugin works. 9 | 10 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 11 | 12 | ### Defaults: 13 | 14 | - OK: established, listen 15 | - WARNING: synSent 16 | - CRITICAL: closed 17 | 18 | Possible values are: closed, listen, synSent, synReceived, established, finWait1, finWait2, closeWait, lastAck, closing, timeWait, deleteTCB 19 | 20 | ### Example: 21 | 22 | #### Check TCP Port 80: 23 | ```./check_snmp_port.py -H 192.168.2.1 -t tcp -p 80 -c established -o closed -w listen``` 24 | ``` 25 | => 26 | Warning - Current TCP status for port 80 is: listen 27 | ``` 28 | 29 | #### Check UDP Port 68: 30 | 31 | ```./check_snmp_port.py -H 192.168.2.1 -t udp -p 68``` 32 | ``` 33 | => 34 | Critical - Current UDP status for port 68 is: CLOSED 35 | ``` 36 | ``` 37 | => 38 | OK - Current UDP status for port 67 is: OPEN 39 | ``` 40 | 41 | #### Show all open UDP Ports: 42 | `./check_snmp_port.py -H 192.168.2.1 -t udp -p scan` 43 | ``` 44 | => 45 | All open UDP ports: 46 | UDP: 53 47 | UDP: 67 48 | UDP: 161 49 | UDP: 1900 50 | UDP: 5353 51 | UDP: 45669 52 | UDP: 5060 53 | UDP: 35678 54 | UDP: 45645 55 | UDP: 47921 56 | UDP: 48306 57 | UDP: 55330 58 | ``` 59 | #### Show all open TCP Ports: 60 | `./check_snmp_port.py -H 192.168.2.1 -t tcp -p scan` 61 | ``` 62 | => 63 | All open TCP ports: 64 | TCP: 53 Status: listen 65 | TCP: 515 Status: listen 66 | TCP: 49152 Status: listen 67 | TCP: 49153 Status: listen 68 | TCP: 49154 Status: listen 69 | TCP: 49155 Status: listen 70 | TCP: 25661 Status: listen 71 | TCP: 80 Status: listen 72 | TCP: 39990 Status: listen 73 | ``` 74 | ### Options 75 | ``` 76 | - -h, --help show this help message and exit 77 | - -H HOSTNAME Hostname or ip address 78 | - --version=VERSION SNMP version (default: 2) 79 | - --community=COMMUNITY SNMP community (default: public) 80 | - -o OK ok values - (possible options: closed, listen, 81 | synSent, synReceived, established, finWait1, finWait2, 82 | closeWait, lastAck, closing, timeWait, deleteTCB) 83 | - -w WARNING warning values 84 | - -c CRITICAL critical vales 85 | - -t TYPE TCP or UDP 86 | - -p PORT The port you want to monitor ('scan' for scanning) 87 | ``` 88 | 89 | ### Running the unit tests 90 | 91 | To run the unittests for check_snmp_port.py: 92 | 93 | apt-get install python-pytest 94 | py.test unittest.py -v --capture=sys 95 | 96 | It's required that SNMPv2 with read cmmunity public is enabled on the host, that runs the test 97 | 98 | ### TODO: 99 | * Implement SNMPv3 100 | * It should be possible to enter a list of ports that should be checked 101 | 102 | -------------------------------------------------------------------------------- /doc/check_snmp_port/example_commands_check_snmp_port.cfg: -------------------------------------------------------------------------------- 1 | 2 | # $ARG1$: the snmp community 3 | # $ARG2$: the port you want to monitor 4 | # $ARG3$: the type of the port (UDP, TCP) 5 | # $ARG4$: For TCP Ports: The status where a warning should be shown 6 | # $ARG5$: For TCP Ports: The status where a critical should be shown 7 | 8 | 9 | define command { 10 | command_name check_snmp_port 11 | command_line /usr/local/bin/check_snmp_port.py -H $HOSTADDRESS$ --community=$ARG1$ -p $ARG2$ -t $ARG3$ $ARG4$ $ARG5$ 12 | } 13 | 14 | -------------------------------------------------------------------------------- /doc/check_snmp_procurve/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_procurve.py: 2 | --- 3 | 4 | Check via SNMP if the sensors for an HP / Aruba Procurve Switch are in good condition. Usually the "Power Supply Sensor" and "Fan Sensor" is available. 5 | The hpicfSensorTable is used to read all available sensors and their status. (MIB: hpicfchassis.mib) 6 | 7 | 8 | ### Example: 9 | 10 | #### Failed Power Supply and failed FAN 11 | ```./check_snmp_procurve.py -H 192.168.2.1 12 | ``` 13 | => 14 | Critical - Fan Sensor: bad. Power Supply 1 Sensor: good. 15 | ``` 16 | 17 | #### Everything OK 18 | ```./check_snmp_procurve.py -H 192.168.2.1 19 | ``` 20 | => 21 | OK - Fan Sensor: good. Power Supply 1 Sensor: good. 22 | ``` 23 | 24 | 25 | ### Options 26 | ``` 27 | - -h, --help show this help message and exit 28 | - -H HOSTNAME Hostname or ip address 29 | - --version=VERSION SNMP version (default: 2) 30 | - --community=COMMUNITY SNMP community (default: public) 31 | ``` 32 | -------------------------------------------------------------------------------- /doc/check_snmp_procurve/example_commands_check_snmp_procurve.cfg: -------------------------------------------------------------------------------- 1 | 2 | # $ARG1$: the snmp community 3 | 4 | define command { 5 | command_name check_snmp_procurve 6 | command_line /usr/local/bin/check_snmp_procurve.py -H $HOSTADDRESS$ --community=$ARG1$ 7 | } 8 | 9 | -------------------------------------------------------------------------------- /doc/check_snmp_raritan/README.md: -------------------------------------------------------------------------------- 1 | # check_snmp_raritan.py 2 | 3 | --- 4 | 5 | Check a Raritan Dominition PX PDU (Power Distribution Unit): 6 | 7 | * outlets (On, Off) 8 | * inlet (Power, Current, Voltage) 9 | * connected sensors 10 | 11 | Tested device: PX2-2486 12 | Tested sensors: Temperature, Humidity, Contact Closure, Air Pressure 13 | 14 | ### Example: 15 | 16 | #### Check the Inlet Power: 17 | 18 | ./check_snmp_raritan.py -H 172.29.1.2 -t inlet 19 | 20 | => 21 | 22 | OK - Inlet. 5.1 A. 230.0 V. 1118.0 W. 1165.0 VA. 0.96. 6904491.0 Wh | 'A'=5.1A;10.4;12.8;; 'V'=230.0V;247.0;254.0;; 'W'=1118.0W;0.0;0.0;; 'VA'=1165.0VA;0.0;0.0;; ''=0.96;0.0;0.0;; 'Wh'=6904491.0Wh;0.0;0.0;; 23 | 24 | #### Monitor sensor with ID 1: 25 | 26 | ./check_snmp_raritan.py -H 172.29.1.2 -t sensor -i 1 27 | 28 | => 29 | 30 | Critical - Sensor 4 - 'On/Off 1' is: alarmed 31 | 32 | => 33 | 34 | OK - Sensor 4 - 'Humidity 1' 18.0% is: normal | 'Humidity 1'=18.0%;70.0;80.0;; 35 | 36 | #### Monitor outlet with ID 3: 37 | 38 | ./check_snmp_raritan.py -H 172.29.1.2 -t outlet -i 3 39 | 40 | => 41 | 42 | Critical - Outlet 3 - 'Switch HP' is: OFF 43 | 44 | #### Monitor outlet via SNMPv3: 45 | 46 | Enable SNMPv3 in SNMP settings of the Raritan device and configure a user that is allowed to login via SNMPv3 in the user management of the device. 47 | 48 | ``` 49 | ./check_snmp_raritan.py -H 172.29.1.2 -t outlet -i 3 -V 3 -U snmpv3 -L authPriv -a MD5 -A snmpv3snmpv3 -x DES -X snmpv3snmpv3 50 | ``` 51 | 52 | => 53 | 54 | ``` 55 | Critical - Outlet 3 - 'Switch HP' is: OFF 56 | ``` 57 | 58 | ## Parameters 59 | 60 | ``` 61 | Options: 62 | -h, --help show this help message and exit 63 | -H HOSTNAME Hostname or ip address 64 | -C COMMUNITY, --community=COMMUNITY 65 | SNMP community of the SNMP service on target host. 66 | -V VERSION, --snmpversion=VERSION 67 | SNMP version. (1 or 2) 68 | -t TYP The type you want to monitor (inlet, outlet, sensor) 69 | -i ID The id of the outlet / sensor you want to monitor 70 | (1-99) 71 | ``` 72 | -------------------------------------------------------------------------------- /doc/check_snmp_raritan/example_commands_check_snmp_raritan.cfg: -------------------------------------------------------------------------------- 1 | 2 | # $ARG1$: the snmp community 3 | # $ARG2$: the check type: inlet, outlet, sensor 4 | # $ARG3$: -i ID: The ID of the sensor, if outlet or sensor is set 5 | 6 | define command { 7 | command_name check_snmp_raritan 8 | command_line /usr/local/bin/check_snmp_raritan.py -H $HOSTADDRESS$ -C $ARG1$ -t $ARG2$ $ARG3$ 9 | } 10 | -------------------------------------------------------------------------------- /doc/check_snmp_service/README.md: -------------------------------------------------------------------------------- 1 | # check_snmp_service.py: 2 | --- 3 | 4 | Icinga / Nagios plugin to check if a Windows service is in running state via SNMP. 5 | 6 | It may take some time until Windows updates the status via snmp after starting or stopping a service. 7 | 8 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 9 | 10 | ### Example: 11 | 12 | #### Check service "Windows Connection Manager": 13 | 14 | ./check_snmp_service.py -H 192.168.2.1 -s "Windows Connection Manager" 15 | 16 | => 17 | 18 | OK - Status of Service 'Windows Connection Manager' is: RUNNING 19 | 20 | => 21 | 22 | Critical - Status of Service 'Windows Connection Manager' is: NOT RUNNING 23 | 24 | #### Show all running services: 25 | 26 | ./check_snmp_service.py -H 192.168.2.1 -S 27 | 28 | ### Options: 29 | 30 | ``` 31 | -h, --help show this help message and exit 32 | -H HOSTNAME Hostname or ip address 33 | -C COMMUNITY, --community=COMMUNITY 34 | SNMP community of the SNMP service on target host. 35 | -V VERSION, --snmpversion=VERSION 36 | SNMP version. (1 or 2) 37 | -s SERVICE The name of the service you want to monitor (-s scan 38 | for scanning) 39 | -S, --scan Show all available services 40 | ``` -------------------------------------------------------------------------------- /doc/check_snmp_service/example_commands_check_snmp_service.cfg: -------------------------------------------------------------------------------- 1 | # ARG1: community 2 | # ARG2: the name of the service 3 | 4 | define command { 5 | command_name check_snmp_service 6 | command_line /usr/local/bin/check_snmp_service.py -H $HOSTADDRESS$ --community=$ARG1$ -s "$ARG2$" 7 | } -------------------------------------------------------------------------------- /doc/check_snmp_teledyne/README.md: -------------------------------------------------------------------------------- 1 | # check_snmp_teledyne.py 2 | --- 3 | 4 | This plugin checks the health of Teledyn Paradise Datacom Sattelite Modem. 5 | 6 | ### Options 7 | ``` 8 | -h, --help show this help message and exit 9 | -H Hostname or ip address 10 | -C, --community SNMP community of the SNMP service on target host. 11 | -V, --snmpversion SNMP version. (1 or 2) 12 | ``` 13 | ``` 14 | 15 | ### Examples 16 | 17 | 18 | ./check_snmp_teledyne.py -H 172.29.1.2 19 | 20 | => 21 | 22 | OK - Fault Summary: No Fault. Power Supply 1: No Fault. Power Supply 2: No Fault. RF Switch 1: No Fault. RF Switch 2: No Fault. Unit 1: No Fault. Unit 2: No Fault. Unit 3: No Fault 23 | Critical - Fault Summary: Fault. Power Supply 1: Fault. Power Supply 2: Fault. RF Switch 1: Fault. RF Switch 2: Fault. Unit 1: Fault. Unit 2: Fault. Unit 3: Fault 24 | -------------------------------------------------------------------------------- /doc/check_snmp_teledyne/example_commands_check_snmp_teledyne.cfg: -------------------------------------------------------------------------------- 1 | # ARG1: the SNMP community 2 | 3 | define command { 4 | command_name check_snmp_teledyne 5 | command_line /usr/bin/check_snmp_teledyne.py -H $HOSTADDRESS$ -C $ARG1$ 6 | } -------------------------------------------------------------------------------- /doc/check_snmp_time2/README.md: -------------------------------------------------------------------------------- 1 | # check_snmp_time2.py 2 | --- 3 | 4 | This plugin compares the time of the icinga/nagios machine with the time of a remote device. 5 | 6 | ### Differences to check_snmp_time.pl 7 | 8 | Up to now we used the check_snmp_time.pl plugin, but we had problems with the daylight saving time. 9 | 10 | - does not need a reconfiguration for summer and wintertime anymore 11 | - works for windows and linux installations 12 | - normally an offset is now unnecessary (so set --tzoffset to 0 or delete it) 13 | - warnings and criticals are now adapted to icinga standard 14 | 15 | ### Options 16 | ``` 17 | -h, --help show this help message and exit 18 | -H Hostname or ip address 19 | -C, --community SNMP community of the SNMP service on target host. 20 | -V, --snmpversion SNMP version. (1 or 2) 21 | -o, --tzoffset the local systems utc offset to the servers utc, in minutes (use only if your 22 | remote device is in a different timezone) 23 | -l, --localtime force to use local time (only recommended if you have a non Windows OS remote device, 24 | that returns localtime and not utc) 25 | --th, --threshold threshold configuration for warning- and critical-threshold to the metric offset 26 | ``` 27 | #### Defaults 28 | ``` 29 | -C, --community "public" 30 | -V, --snmpversion 2 31 | -o, --tzoffset 0 32 | ``` 33 | 34 | ### Examples 35 | 36 | 37 | #### check with custom warning and critical threshold 38 | 39 | ./check_snmp_time2.py -H 192.168.2.1 --th metric=offset,warning=-5:5,critical=-15:15 40 | 41 | => 42 | 43 | OK - Remote UTC: 20:23:49. Offset = 0 s | 'offset'=0.0s;;;; 44 | 45 | 46 | #### forced check with localtime 47 | 48 | ./check_snmp_time2.py -H 192.168.2.1 -l 49 | 50 | Not all devices return the time as UTC time. For example Windows return the local time. 51 | With this parameter the script compares the time from the remote device, with the local time (instead of UTC) of the nagios/icinga machine. 52 | 53 | -------------------------------------------------------------------------------- /doc/check_snmp_time2/example_commands_check_snmp_time2.cfg: -------------------------------------------------------------------------------- 1 | # ARG1: the community 2 | # ARG2: the offset 3 | # ARG3: the warning threshold 4 | # ARG4: the critical threshold 5 | 6 | define command { 7 | command_name check_snmp_time 8 | command_line /usr/local/bin/check_snmp_time2.py -H $HOSTADDRESS$ -C $ARG1$ --threshold metric=offset,warning=$ARG3$,critical=$ARG4$ --tzoffset=$ARG2$ 9 | } -------------------------------------------------------------------------------- /doc/check_snmp_ubiquiti/README.md: -------------------------------------------------------------------------------- 1 | ## check_snmp_ubiquiti.py: 2 | 3 | Check the status of a Ubiquiti device. 4 | 5 | You can check the 6 | 7 | - Uptime 8 | - Signal Strength 9 | - CPU usage (1 Minute Average) 10 | - CPU usage (5 Minute Average) 11 | - CPU usage (15 Minute Average) 12 | - Total memory 13 | - Free memory 14 | - Tx Rate 15 | - Rx Rate 16 | The plugin requires pynag (https://github.com/pynag/pynag) and python-netsnmp. 17 | 18 | Example: 19 | 20 | Get a list of all possible types 21 | ``` 22 | ./check_ubiquiti.py -l 23 | ``` 24 | Check uL1 with warning(-10:10) and critical(-20:20) metrics (pynag standard confirm): 25 | ``` 26 | ./check_ubiquiti.py -H 192.168.2.12 -t up --th metric=type,warning=-10:10,critical=-20:20 27 | ``` 28 | Check uL1 without pynag metrics: 29 | ``` 30 | ./check_ubiquiti.py -H 192.168.2.12 -t up 31 | ``` 32 | Options 33 | ``` 34 | -h, --help show this help message and exit 35 | -l, --list lists all possible request types 36 | -H HOSTNAME, --hostname=HOSTNAME Host name or IP Adress of hte MOXA device. 37 | -C COMMUNITY, --community=COMMUNITY SNMP community of the SNMP service on target host. 38 | -V SNMPVERSION, --snmpversion=SNMPVERSION SNMP version. 39 | -t TYPE, --type=TYPE type of the request 40 | --th metric=type,warning=WARNING_MIN:WARNING_MAX,critical=CRITICAL_MIN:CRITICAL_MAX add warning and critical values pynag confirm 41 | ``` 42 | -------------------------------------------------------------------------------- /health_monitoring_plugins/cambium.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module for cambium 3 | """ 4 | # Copyright (C) 2018-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | from pynag.Plugins import unknown, warning, critical 22 | 23 | # OIDS 24 | CONNECTION_OIDS = { 25 | "search_state": '.1.3.6.1.4.1.17713.9.12.16.0' 26 | } 27 | 28 | 29 | # STATES 30 | 31 | SEARCH_STATE = { 32 | 0: 'registering / connected', 33 | 1: 'searching / not connected', 34 | 2: 'acquiring / connecting' 35 | } 36 | 37 | class PTP700(object): 38 | 39 | def __init__(self, session): 40 | self.sess = session 41 | 42 | @staticmethod 43 | def get_connection_info(helper, session): 44 | """ get the infos for the connection """ 45 | 46 | value = helper.get_snmp_values_or_exit(session, helper, CONNECTION_OIDS["search_state"])[0] 47 | try: 48 | value = int(value) 49 | except: 50 | return "N//A" 51 | 52 | status = SEARCH_STATE.get(value, "N/A") 53 | 54 | return status 55 | 56 | 57 | def process_connection_status(self, helper, session): 58 | """ 59 | check the status of the connection 60 | """ 61 | 62 | search_state = self.get_connection_info(helper, session) 63 | 64 | helper.add_summary("Radio is {}".format(search_state)) 65 | 66 | if search_state != "registering / connected": 67 | helper.status(critical) -------------------------------------------------------------------------------- /health_monitoring_plugins/check_jenkins_api/check_jenkins_api.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # check_jenkins_api.py - Check the Jenkins queue. If there are jobs for more than X hours, critical will be shown. 3 | 4 | # Copyright (C) 2018-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | # Import PluginHelper and some utility constants from the Plugins module 22 | import sys 23 | import os 24 | import urllib2 25 | import json 26 | import base64 27 | from datetime import datetime 28 | sys.path.insert(1, os.path.join(sys.path[0], os.pardir)) 29 | from pynag.Plugins import PluginHelper, ok, critical, unknown, warning 30 | 31 | # Create an instance of PluginHelper() 32 | helper = PluginHelper() 33 | helper.parser.add_option('-p', help="the port the Jenkins webserver (default: 80)", dest="port", default="80") 34 | helper.parser.add_option('-H', help="the IP address or hostname of the Jenkins", dest="host", default="127.0.0.1") 35 | helper.parser.add_option('-U', help="the user for the basic authentication", dest="user", default="user") 36 | helper.parser.add_option('-P', help="the password for the basic authentication or the API token", dest="password", default="password") 37 | helper.parser.add_option('--PWF', help="a file containing the password", dest="pwf") 38 | helper.parser.add_option('-A', help="the maximum age of a Jenkins job in hours", dest="age") 39 | helper.parser.add_option('-S', help="check if Jenkins is in shudown mode", dest="shutdown", default=False, action='store_true') 40 | helper.parser.add_option('-D', help="check if a Jenkins executor is disconnected", dest="disconnect", default=False, action='store_true') 41 | 42 | 43 | helper.parse_arguments() 44 | 45 | # get the options 46 | port = helper.options.port 47 | host = helper.options.host 48 | user = helper.options.user 49 | password = helper.options.password 50 | if helper.options.age: 51 | age = float(helper.options.age) 52 | else: 53 | age = None 54 | shutdown = helper.options.shutdown 55 | disconnect = helper.options.disconnect 56 | pwf = helper.options.pwf 57 | 58 | if pwf: 59 | with open(pwf, 'r') as myfile: 60 | password=myfile.read().replace('\n', '') 61 | 62 | # The default return value should be always OK 63 | helper.status(ok) 64 | helper.add_summary("%s" % host) 65 | 66 | if __name__ == "__main__": 67 | 68 | if age: 69 | helper.add_summary("job queue:") 70 | # query the data from the Jenkins JSON API 71 | url = "http://%s/queue/api/json?pretty=true:%s" % (host, port) 72 | 73 | request = urllib2.Request(url) 74 | base64string = base64.b64encode('%s:%s' % (user, password)) 75 | request.add_header("Authorization", "Basic %s" % base64string) 76 | response = urllib2.urlopen(request) 77 | data = json.loads(response.read()) 78 | 79 | # check every job in the build queue 80 | for item in data['items']: 81 | starttime = item['inQueueSince'] 82 | # quick and dirty 83 | starttime = datetime.fromtimestamp(float(starttime/1000)) 84 | currenttime = datetime.today() 85 | waitingfor = abs(currenttime - starttime).total_seconds() / 3600.0 86 | 87 | if waitingfor > age: 88 | helper.status(critical) 89 | helper.add_summary("JENKINS JOB WAITING FOR %s hours - CHECK INSTANCES" % (waitingfor)) 90 | 91 | elif shutdown: 92 | helper.add_summary("shutdown status:") 93 | # query the data from the Jenkins JSON API 94 | url = "http://%s/api/json?pretty=true:%s" % (host, port) 95 | 96 | request = urllib2.Request(url) 97 | base64string = base64.b64encode('%s:%s' % (user, password)) 98 | request.add_header("Authorization", "Basic %s" % base64string) 99 | response = urllib2.urlopen(request) 100 | data = json.loads(response.read()) 101 | 102 | if data["quietingDown"] is True: 103 | helper.status(warning) 104 | helper.add_summary("JENKINS IS IN SHUTDOWN MODE") 105 | 106 | elif disconnect: 107 | helper.add_summary("executor status:") 108 | # query the data from the Jenkins JSON API 109 | url = "http://%s/computer/api/json?pretty=true:%s" % (host, port) 110 | 111 | request = urllib2.Request(url) 112 | base64string = base64.b64encode('%s:%s' % (user, password)) 113 | request.add_header("Authorization", "Basic %s" % base64string) 114 | response = urllib2.urlopen(request) 115 | data = json.loads(response.read()) 116 | 117 | for computer in data['computer']: 118 | 119 | if computer["temporarilyOffline"] is True: 120 | helper.status(warning) 121 | helper.add_summary("Jenkins executor temporarily offline") 122 | 123 | if computer["offline"] is True: 124 | helper.status(critical) 125 | helper.add_summary("Jenkins executor temporarily offline") 126 | 127 | else: 128 | helper.status(unknown) 129 | helper.add_summary("Missing parameter") 130 | helper.exit() 131 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_local_cpu_temperature/check_local_cpu_temperature.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # check_local_cpu_temperature.py - Check the local CPU temperature without the usage of "lm-sensors" 3 | 4 | # Copyright (C) 2018-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | # Import PluginHelper and some utility constants from the Plugins module 22 | import sys 23 | import os 24 | from pynag.Plugins import PluginHelper, ok, critical, unknown, warning 25 | sys.path.insert(1, os.path.join(sys.path[0], os.pardir)) 26 | 27 | 28 | # Create an instance of PluginHelper() 29 | helper = PluginHelper() 30 | helper.parser.add_option('-C', help="check the component (temp1, Core 0, Core 1, Core x)", 31 | dest="component", default='Core 0') 32 | 33 | helper.parse_arguments() 34 | 35 | # get the options 36 | component = helper.options.component 37 | 38 | 39 | # The default return value should be always OK 40 | helper.status(ok) 41 | 42 | 43 | def read_temperature(sensors_filefile): 44 | try: 45 | with open(sensors_file) as f: 46 | content = f.readlines() 47 | 48 | content = [x.strip() for x in content] 49 | temperature = float(content[0])/1000 50 | 51 | return temperature 52 | 53 | except: 54 | helper.exit(summary="not able to read data - sensor not available" , exit_code=unknown, perfdata='') 55 | 56 | 57 | if __name__ == "__main__": 58 | 59 | if component == "temp1": 60 | # read the data 61 | sensors_file = "/sys/class/thermal/thermal_zone0/temp" 62 | temperature = read_temperature(sensors_file) 63 | 64 | # Show the summary and add the metric and afterwards check the metric 65 | helper.add_summary("CPU temperature: %s C" % temperature) 66 | helper.add_metric(label='temp',value=temperature) 67 | 68 | elif "Core" in component: 69 | core = int(component.split(" ")[1]) 70 | sensors_file = ("/sys/devices/platform/coretemp.0/hwmon/hwmon1/temp%s_input" % (core+2)) 71 | temperature = read_temperature(sensors_file) 72 | 73 | # Show the summary and add the metric and afterwards check the metric 74 | helper.add_summary("Core %s temperature: %s C" % (core, temperature)) 75 | helper.add_metric(label='temp',value=temperature) 76 | 77 | helper.check_all_metrics() 78 | 79 | helper.exit() 80 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_meinberg_ntp/check_meinberg_ntp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # check_meinberg_ntp.py - Monitor the Meinberg NTP Server M300. 3 | 4 | # Copyright (C) 2016-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | from pynag.Plugins import ok 22 | import health_monitoring_plugins.meinberg 23 | 24 | if __name__ == "__main__": 25 | # pylint: disable=C0103 26 | helper = health_monitoring_plugins.SnmpHelper() 27 | helper.parser.add_option('-m', 28 | help="Version of the Firmware (v5 or NG) " 29 | "(NG = MBG-LANTIME-NG-MIB.mib used in Firmware 6 and newer)", 30 | dest="mibversion") 31 | helper.parse_arguments() 32 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 33 | 34 | # The default return value should be always OK 35 | helper.status(ok) 36 | 37 | meinberg = health_monitoring_plugins.meinberg.Meinberg(sess, helper.options.mibversion) 38 | 39 | # GPSPosition 40 | meinberg.process_gps_position(helper, sess) 41 | 42 | # NTP Status 43 | meinberg.process_status(helper, sess, 'ntp_current_state') 44 | 45 | # GPS Status 46 | meinberg.process_status(helper, sess, 'gps_mode') 47 | 48 | # Satellites 49 | meinberg.process_satellites(helper, sess) 50 | 51 | # there is only the satellites metric, but we will check all available 52 | helper.check_all_metrics() 53 | 54 | # Print out plugin information and exit nagios-style 55 | helper.exit() 56 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_microwavemodem/check_microwavemodem.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (C) 2019 haxtibal haxtibal@posteo.de 4 | 5 | import netsnmp 6 | import health_monitoring_plugins 7 | import health_monitoring_plugins.microwavemodem as microwavemodem 8 | 9 | if __name__ == '__main__': 10 | helper = health_monitoring_plugins.SnmpHelper() 11 | helper.parser.add_option('-m', '--modem', type='choice', choices=['SK-IP', 'AX-60'], help="Select modem model.") 12 | helper.parse_arguments() 13 | 14 | if (not helper.options.hostname): 15 | helper.parser.error("Host not specified.") 16 | if helper.options.modem == 'SK-IP': 17 | modem = microwavemodem.TYPE_SKIP 18 | elif helper.options.modem == 'AX-60': 19 | modem = microwavemodem.TYPE_AX60 20 | else: 21 | helper.parser.error("Modem type not specified or unknown.") 22 | 23 | snmp_session = netsnmp.Session(**helper.get_snmp_args()) 24 | microwavemodem = microwavemodem.MicrowaveModem(modem, snmp_session) 25 | microwavemodem.check() 26 | microwavemodem.feed_icinga_plugin(helper) 27 | helper.exit() 28 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (C) 2019 haxtibal haxtibal@posteo.de 4 | 5 | import netsnmp 6 | import health_monitoring_plugins 7 | import health_monitoring_plugins.newtecmodem as newtecmodem 8 | 9 | if __name__ == '__main__': 10 | helper = health_monitoring_plugins.SnmpHelper() 11 | helper.parser.add_option('-m', '--modem', type='choice', choices=['MDM6000', 'MDM9000'], help="Select modem model.") 12 | helper.parse_arguments() 13 | 14 | if (not helper.options.hostname): 15 | helper.parser.error("Host not specified.") 16 | if helper.options.modem == 'MDM6000': 17 | modem = newtecmodem.TYPE_MDM6000 18 | elif helper.options.modem == 'MDM9000': 19 | modem = newtecmodem.TYPE_MDM9000 20 | else: 21 | helper.parser.error("Modem type not specified or unknown.") 22 | 23 | snmp_session = netsnmp.Session(**helper.get_snmp_args()) 24 | newtecmodem_health = newtecmodem.NewtecModem(modem, snmp_session) 25 | newtecmodem_health.check() 26 | newtecmodem_health.feed_icinga_plugin(helper) 27 | helper.exit() 28 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # snmp_cambium_ptp700.py - Monitor the Cambium PTP700 radio. 3 | 4 | # Copyright (C) 2016-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | from pynag.Plugins import ok 22 | import health_monitoring_plugins.cambium 23 | 24 | if __name__ == "__main__": 25 | # pylint: disable=C0103 26 | helper = health_monitoring_plugins.SnmpHelper() 27 | #helper.parser.add_option('-m', 28 | # help="Version of the Firmware (v5 or NG) " 29 | # "(NG = MBG-LANTIME-NG-MIB.mib used in Firmware 6 and newer)", 30 | # dest="mibversion") 31 | helper.parse_arguments() 32 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 33 | 34 | # The default return value should be always OK 35 | helper.status(ok) 36 | 37 | cambium = health_monitoring_plugins.cambium.PTP700(sess) 38 | 39 | # Connection status 40 | cambium.process_connection_status(helper, sess) 41 | 42 | # there is only the satellites metric, but we will check all available 43 | #helper.check_all_metrics() 44 | 45 | # Print out plugin information and exit nagios-style 46 | helper.exit() 47 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_eaton_ups/check_snmp_eaton_ups.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # check_snmp_apc_ups.py - Check a Eaton APC UPS health state via SNMP 4 | # implementing upsMIB and xupsMIB 5 | 6 | # Copyright (C) 2016-2019 rsmuc 7 | 8 | # This file is part of "Health Monitoring Plugins". 9 | 10 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation, either version 2 of the License, or 13 | # (at your option) any later version. 14 | 15 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | 20 | # You should have received a copy of the GNU General Public License 21 | # along with "Health Monitoring Plugins". If not, see . 22 | 23 | 24 | # Import PluginHelper and some utility constants from the Plugins module 25 | from pynag.Plugins import unknown 26 | import health_monitoring_plugins.eaton 27 | 28 | if __name__ == "__main__": 29 | 30 | # pylint: disable=C0103 31 | 32 | helper = health_monitoring_plugins.SnmpHelper() 33 | helper.parser.add_option('-t', '--type', dest='type', 34 | help="Check type to execute. Available types are: {}".format( 35 | ', '.join(health_monitoring_plugins.eaton.available_types())), 36 | type='str') 37 | helper.parse_arguments() 38 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 39 | eaton_ups = health_monitoring_plugins.eaton.EatonUPS(sess, helper) 40 | if helper.options.type in health_monitoring_plugins.eaton.available_types(): 41 | eaton_ups.check_generic_status() 42 | else: 43 | helper.exit( 44 | summary="Invalid check type {} specified or not available".format(helper.options.type), 45 | exit_code=unknown, 46 | perfdata='') 47 | helper.exit() 48 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_eps_plus/check_snmp_eps_plus.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (C) 2016-2019 rsmuc 4 | 5 | # This file is part of "Health Monitoring Plugins". 6 | 7 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 2 of the License, or 10 | # (at your option) any later version. 11 | 12 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with "Health Monitoring Plugins". If not, see . 19 | 20 | from pynag.Plugins import ok, unknown 21 | import health_monitoring_plugins.eps_plus 22 | 23 | if __name__ == '__main__': 24 | # pylint: disable=C0103 25 | helper = health_monitoring_plugins.SnmpHelper() 26 | 27 | helper.parser.add_option('--device', help='Select the device whose outlet shall be monitored ' 28 | '(0 = master, 1 = first slave, 2 = second slave)', 29 | default=None, type='str', dest='device') 30 | helper.parser.add_option('--outlet', help='Select the outlet which shall be monitored ' 31 | '(0 = first outlet)', 32 | default=None, type='str', dest='outlet') 33 | 34 | helper.parser.add_option('--expected', help='Define if On or Off shall be the OK sate ' 35 | '(On, Off)', 36 | default="On", dest='expected') 37 | 38 | helper.parser.add_option('--sensor', help='Select the sensor which shall be monitored ' 39 | '(T1, T2, Tx, H1, H2, Hx)', 40 | default=None, dest='sensor') 41 | 42 | 43 | helper.parse_arguments() 44 | 45 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 46 | 47 | # The default return value should be always OK 48 | helper.status(ok) 49 | 50 | eps_plus = health_monitoring_plugins.eps_plus.EPSplus() 51 | 52 | # Outlet 53 | if helper.options.device is not None and helper.options.outlet is not None: 54 | eps_plus.check_outlet(helper, sess) 55 | 56 | # Sensor 57 | elif helper.options.sensor: 58 | eps_plus.check_sensor(helper, sess) 59 | 60 | else: 61 | helper.exit(summary="Please select --device and --outlet or --sensor", 62 | exit_code=unknown, perfdata='') 63 | 64 | # check all metrics we added 65 | helper.check_all_metrics() 66 | 67 | # Print out plugin information and exit nagios-style 68 | helper.exit() 69 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_idrac/check_snmp_idrac.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (C) 2016-2019 rsmuc 4 | 5 | # This file is part of "Health Monitoring Plugins". 6 | 7 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 2 of the License, or 10 | # (at your option) any later version. 11 | 12 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with "Health Monitoring Plugins". If not, see . 19 | 20 | from pynag.Plugins import ok 21 | import health_monitoring_plugins.idrac 22 | 23 | if __name__ == '__main__': 24 | # pylint: disable=C0103 25 | helper = health_monitoring_plugins.SnmpHelper() 26 | 27 | helper.parser.add_option('--no-system', help='Do not check the global system status', 28 | default=True, action='store_false', dest='system') 29 | helper.parser.add_option('--no-power', help='Do not check the power status', 30 | default=True, action='store_false', dest='power') 31 | helper.parser.add_option('--no-storage', help='Do not check the storage status', 32 | default=True, action='store_false', dest='storage') 33 | helper.parser.add_option('--no-disks', help='Do not check the disks', 34 | default=True, action='store_false', dest='disks') 35 | helper.parser.add_option('--no-predictive', help='Do not check the predictive status of the disks', 36 | default=True, action='store_false', dest='predictive') 37 | helper.parser.add_option('--no-lcd', help='Do not check the lcd status', 38 | default=True, action='store_false', dest='lcd') 39 | helper.parser.add_option('--no-power_unit', help='Do not check the power unit', 40 | default=True, action='store_false', dest='power_unit') 41 | helper.parser.add_option('--no-redundancy', help='Do not check the power unit redundancy', 42 | default=True, action='store_false', dest='power_unit_redundancy') 43 | helper.parser.add_option('--no-intrusion', help='Do not check the intrusion sensor', 44 | default=True, action='store_false', dest='intrusion') 45 | helper.parser.add_option('--no-cooling', help='Do not check the cooling unit', 46 | default=True, action='store_false', dest='cooling_unit') 47 | helper.parser.add_option('--no-temperature', help='Do not check the temperature', 48 | default=True, action='store_false', dest='temperature') 49 | 50 | helper.parse_arguments() 51 | 52 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 53 | 54 | # The default return value should be always OK 55 | helper.status(ok) 56 | 57 | idrac = health_monitoring_plugins.idrac.Idrac(sess) 58 | 59 | # Device information 60 | idrac.add_device_information(helper, sess) 61 | 62 | # SYSTEM STATUS 63 | if helper.options.system: 64 | idrac.process_status(helper, sess, "global_system") 65 | 66 | # SYSTEM POWER STATUS 67 | if helper.options.power: 68 | idrac.process_status(helper, sess, "system_power") 69 | 70 | # SYSTEM STORAGE STATUS 71 | if helper.options.storage: 72 | idrac.process_status(helper, sess, "global_storage") 73 | 74 | # LCD STATUS 75 | if helper.options.lcd: 76 | idrac.process_status(helper, sess, "system_lcd") 77 | 78 | # DISK STATES 79 | if helper.options.disks: 80 | idrac.process_states(helper, sess, "drive") 81 | 82 | # PREDICTIVE SMART DISK STATUS 83 | if helper.options.predictive: 84 | idrac.process_states(helper, sess, "predictive_drive_status") 85 | 86 | # POWER UNIT Status 87 | if helper.options.power_unit: 88 | idrac.process_states(helper, sess, "power_unit") 89 | 90 | # POWER UNIT Redundancy Status 91 | if helper.options.power_unit_redundancy: 92 | idrac.process_states(helper, sess, "power_unit_redundancy") 93 | 94 | # CHASSIS INTRUSION Status 95 | if helper.options.intrusion: 96 | idrac.process_states(helper, sess, "chassis_intrusion") 97 | 98 | # COOLING UNIT Status 99 | if helper.options.cooling_unit: 100 | idrac.process_states(helper, sess, "cooling_unit") 101 | 102 | # Temperature Sensors 103 | if helper.options.temperature: 104 | idrac.process_temperature_sensors(helper, sess) 105 | 106 | # check all metrics we added 107 | helper.check_all_metrics() 108 | 109 | # Print out plugin information and exit nagios-style 110 | helper.exit() 111 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_inradios_csm/check_snmp_inradios_csm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (C) 2018-2019 haxtibal haxtibal@posteo.de 4 | 5 | # This file is part of "Health Monitoring Plugins". 6 | 7 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 2 of the License, or 10 | # (at your option) any later version. 11 | 12 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with "Health Monitoring Plugins". If not, see . 19 | import netsnmp 20 | import health_monitoring_plugins.inradios_csm 21 | 22 | if __name__ == '__main__': 23 | helper = health_monitoring_plugins.SnmpHelper() 24 | helper.parser.add_option('-i', '--id', dest='id', type="int", 25 | help='Identify a measurement. See description of INRADIOS::csmMonitoringTableIndex.') 26 | helper.parse_arguments() 27 | if (not helper.options.hostname): 28 | helper.parser.error("Server not specified.") 29 | if (not helper.options.id): 30 | helper.parser.error("Measurement id not specified.") 31 | snmp_session = netsnmp.Session(**helper.get_snmp_args()) 32 | inradios_health = health_monitoring_plugins.inradios_csm.InradiosCsmHealth(snmp_session, helper.options.id) 33 | inradios_health.check() 34 | inradios_health.feed_icinga_plugin(helper) 35 | helper.exit() -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_janitza/check_snmp_janitza.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # check_snmp_janitza.py - Monitor the Janitza 604 via SNMP. 4 | 5 | # Copyright (C) 2016 Retakfual 6 | # 2016-2019 rsmuc 7 | 8 | 9 | # This file is part of "Health Monitoring Plugins". 10 | 11 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 12 | # it under the terms of the GNU General Public License as published by 13 | # the Free Software Foundation, either version 2 of the License, or 14 | # (at your option) any later version. 15 | 16 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | 21 | # You should have received a copy of the GNU General Public License 22 | # along with "Health Monitoring Plugins". If not, see . 23 | 24 | 25 | # Imports 26 | from pynag.Plugins import PluginHelper,ok,warning,critical,unknown 27 | import commands, sys, argparse, math 28 | import netsnmp 29 | import os 30 | sys.path.insert(1, os.path.join(sys.path[0], os.pardir)) 31 | from snmpSessionBaseClass import add_common_options, get_common_options, verify_host, get_data 32 | 33 | # Create an instance of PluginHelper() 34 | helper = PluginHelper() 35 | 36 | # Define the command line options 37 | add_common_options(helper) 38 | helper.parser.add_option('-t', '--type', dest='power_Status', help='Select a Type, for a list of all possible Types use the argument -l') 39 | helper.parser.add_option('-l', '--list', dest='listFlag', default='False', action='store_true', help='Lists all output possibilities') 40 | helper.parse_arguments() 41 | 42 | status = helper.options.power_Status 43 | flag_list = helper.options.listFlag 44 | host, version, community = get_common_options(helper) 45 | 46 | 47 | basicoid = '.1.3.6.1.4.1.34278.' 48 | output =[] 49 | 50 | oid = ['1.1.0', '1.2.0', '1.3.0', '1.7.0', '1.8.0', '1.9.0', '1.10.0', '1.11.0', '1.12.0', '1.13.0', '1.14.0', '1.15.0', '1.16.0', '1.17.0', '1.18.0', 51 | '1.19.0', '1.20.0', '1.21.0', '1.22.0', '1.23.0', '1.24.0', '2.1.0', '2.2.0', '2.3.0', '1.4.0', '1.5.0', '1.6.0'] 52 | 53 | names = [ 'uL1', 'uL2', 'uL3', 'iL1', 'iL2', 'iL3', 'iL4', 'iL5', 'iL6', 'pL1', 'pL2', 'pL3', 'qL1', 'qL2', 'qL3', 54 | 'sL1', 'sL2', 'sL3', 'cosPL1', 'cosPL2', 'cosPL3', 'p3', 'q3', 's3', 'uL1L2', 'uL2L3', 'uL3L1'] 55 | 56 | 57 | descriptions=['Voltage Phase L1 in 100mV','Voltage Phase L2 in 100mV','Voltage Phase L3 in 100mV','Current Phase L1 in 1mA','Current Phase L2 in 1mA', 58 | 'Current Phase L3 in 1mA','Current Phase L4 in 1mA','Current Phase L5 in 1mA','Current Phase L6 in 1mA','Real Power L1 in Watt','Real Power L2 in Watt','Real Power L3 in Watt', 59 | 'Reaktiv Power L1 in VAr','Reaktiv Power L2 in VAr','Reaktiv Power L3 in VAr','Power L1 in VA','Power L2 in VA','Power L3 in VA','Cos(Phi) L1 * 0.001', 60 | 'Cos(Phi) L2 * 0.001','Cos(Phi) L3 * 0.001','Real Power Summe L1..L3 in Watt','Reaktiv Power Summe L1..L3 in Watt','Power Summe L1..L3 in Watt', 61 | 'Voltage L1-L2','Voltage L2-L3','Voltage L3-L1'] 62 | 63 | 64 | ############## 65 | ## Main ## 66 | ############### 67 | if __name__ == '__main__': 68 | # The default return value should be always OK 69 | helper.status(ok) 70 | 71 | # shows the list of possible types if the flag is set 72 | if flag_list == True: 73 | for w,v in zip(names, descriptions): 74 | print w + ' = ' + v 75 | helper.status(unknown) 76 | helper.exit(summary='This is just a list and not a check!') 77 | 78 | # verify that a hostname is set 79 | verify_host(host, helper) 80 | 81 | # open session after validated host 82 | sess = netsnmp.Session(Version=version, DestHost=host, Community=community) 83 | 84 | # verify, that status(/type) parameter is not empty 85 | if (status == None) or (status not in names): 86 | helper.status(unknown) 87 | helper.exit(summary='Argument -t is missing or false!') 88 | 89 | # snmp gets for all oids in type-list 90 | ind = names.index(status) 91 | value = get_data(sess, basicoid+oid[ind],helper) 92 | 93 | # metric compares 94 | helper.add_metric(label='type', value = value, uom =' '+descriptions[ind]+' ') 95 | helper.check_all_metrics() 96 | 97 | # programm end 98 | helper.exit() 99 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # check_snmp_large_storage.py - Check the used / free disk space of a device via SNMP 4 | # (using the HOST-RESOURCES-MIB hrStorageSize). 5 | 6 | # Copyright (C) 2016-2019 rsmuc 7 | 8 | # This file is part of "Health Monitoring Plugins". 9 | 10 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation, either version 2 of the License, or 13 | # (at your option) any later version. 14 | 15 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | 20 | # You should have received a copy of the GNU General Public License 21 | # along with "Health Monitoring Plugins". If not, see . 22 | 23 | # Import PluginHelper and some utility constants from the Plugins module 24 | 25 | from __future__ import absolute_import, division, print_function 26 | from pynag.Plugins import ok 27 | import health_monitoring_plugins.storage 28 | 29 | if __name__ == '__main__': 30 | # pylint: disable=C0103 31 | helper = health_monitoring_plugins.SnmpHelper() 32 | 33 | helper.parser.add_option('-p', '--partition', 34 | dest='partition', 35 | help='The disk / partition you want to monitor', 36 | type='str') 37 | helper.parser.add_option('-u', '--unit', dest="targetunit", 38 | help="The unit you want to have (MB, GB, TB)", default="GB") 39 | helper.parser.add_option('-s', '--scan', dest='scan_flag', default=False, action="store_true", 40 | help='Show all available storages') 41 | 42 | helper.parse_arguments() 43 | 44 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 45 | 46 | # The default return value should be always OK 47 | helper.status(ok) 48 | 49 | storage = health_monitoring_plugins.storage.Storage(sess) 50 | 51 | # if no partition is set, we will do a scan; or if scan_flag is set 52 | if helper.options.partition == "" or \ 53 | helper.options.partition is None or \ 54 | helper.options.scan_flag: 55 | # Device information 56 | # run_scan() 57 | storage.run_scan(helper, sess) 58 | 59 | # the check for the defined partition 60 | else: 61 | storage.check_partition(helper, sess) 62 | 63 | helper.check_all_metrics() 64 | 65 | # Print out plugin information and exit nagios-style 66 | helper.exit() 67 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # check_snmp_lband.py - Monitor a L-band redundancy controller via SNMP. 4 | 5 | # Copyright (C) 2017-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | import sys 23 | import os 24 | import netsnmp 25 | sys.path.insert(1, os.path.join(sys.path[0], os.pardir)) 26 | from snmpSessionBaseClass import add_common_options, get_common_options, verify_host, get_data 27 | from pynag.Plugins import PluginHelper,ok,warning,critical,unknown 28 | 29 | # Create an instance of PluginHelper() 30 | helper = PluginHelper() 31 | 32 | # Define the command line options 33 | add_common_options(helper) 34 | helper.parser.add_option('-U', '--unit', dest='unit', help='Select the unit you want to monitor, if no unit is selected both units will be monitored', default="1") 35 | helper.parse_arguments() 36 | 37 | # get the options 38 | host, version, community = get_common_options(helper) 39 | unit = helper.options.unit 40 | 41 | # OIDs from 2082-141.mib.txt 42 | unit1_oid = ".1.3.6.1.4.1.31210.52.1.9.0" 43 | unit2_oid = ".1.3.6.1.4.1.31210.52.1.13.0" 44 | 45 | status = { 46 | "0" : "Online", 47 | "1" : "Standby", 48 | "2" : "Alarmed" 49 | } 50 | 51 | if __name__ == "__main__": 52 | 53 | # verify that a hostname is set 54 | verify_host(host, helper) 55 | 56 | # The default return value should be always OK 57 | helper.status(ok) 58 | 59 | sess = netsnmp.Session(Version=version, DestHost=host, Community=community) 60 | 61 | # get the values 62 | if unit == "1": 63 | value = get_data(sess, unit1_oid, helper) 64 | elif unit == "2": 65 | value = get_data(sess, unit2_oid, helper) 66 | else: 67 | helper.exit(summary="Wrong unit specified", exit_code=unknown, perfdata='') 68 | 69 | 70 | # add the summary 71 | helper.add_summary("Unit status is: %s" % (status[value])) 72 | 73 | if value == "2": 74 | helper.status(critical) 75 | 76 | # Print out plugin information and exit nagios-style 77 | helper.exit() 78 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_port/check_snmp_port.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # check_snmp_port.py - Check the status of a tcp/udp port via SNMP. 3 | 4 | # Copyright (C) 2016-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | # Import PluginHelper and some utility constants from the Plugins module 22 | from __future__ import absolute_import, division, print_function 23 | from pynag.Plugins import ok 24 | import health_monitoring_plugins.ipport 25 | 26 | if __name__ == '__main__': 27 | # pylint: disable=C0103 28 | helper = health_monitoring_plugins.SnmpHelper() 29 | 30 | helper.parser.add_option('-p', '--port', dest='port', help='The port you want to monitor', 31 | type='str', default='') 32 | helper.parser.add_option('-s', '--scan', dest='scan_flag', default=False, action="store_true", 33 | help='Show all open ports') 34 | helper.parser.add_option('-t', '--type', dest="type", help="TCP or UDP", default="udp") 35 | helper.parser.add_option('-w', dest="warning", help="warning values", default="synSent") 36 | helper.parser.add_option('-c', dest="critical", help="critical vales", default="closed") 37 | 38 | helper.parse_arguments() 39 | 40 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 41 | 42 | # The default return value should be always OK 43 | helper.status(ok) 44 | 45 | ipport = health_monitoring_plugins.ipport.Port(sess) 46 | 47 | if helper.options.scan_flag: 48 | ipport.run_scan(helper, sess) 49 | 50 | if helper.options.type.lower() == "udp" and not helper.options.scan_flag: 51 | ipport.check_port(helper) 52 | ipport.check_udp(helper, sess) 53 | 54 | elif helper.options.type.lower() == "tcp" and not helper.options.scan_flag: 55 | ipport.check_port(helper) 56 | ipport.check_tcp(helper, sess) 57 | 58 | # Print out plugin information and exit nagios-style 59 | helper.exit() 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_procurve/check_snmp_procurve.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # check_snmp_procurve.py - Check the sensors of HP / Aruba procurve switches via SNMP 3 | 4 | # Copyright (C) 2017-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | from __future__ import absolute_import, division, print_function 22 | from pynag.Plugins import ok 23 | import health_monitoring_plugins.procurve 24 | 25 | if __name__ == '__main__': 26 | # pylint: disable=C0103 27 | helper = health_monitoring_plugins.SnmpHelper() 28 | 29 | helper.parse_arguments() 30 | 31 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 32 | 33 | # The default return value should be always OK 34 | helper.status(ok) 35 | 36 | procurve = health_monitoring_plugins.procurve.Procurve(sess) 37 | 38 | procurve.check_sensors(helper, sess) 39 | 40 | helper.check_all_metrics() 41 | 42 | helper.exit() 43 | 44 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_raritan/check_snmp_raritan.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # check_snmp_raritan.py - Check a Raritan Dominition PX PDU (Power Distribution Unit), the inlets, outlets and the connected sensors 4 | 5 | # Copyright (C) 2016-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | import health_monitoring_plugins.raritan 23 | from pynag.Plugins import ok 24 | 25 | if __name__ == "__main__": 26 | helper = health_monitoring_plugins.SnmpHelper() 27 | helper.parser.add_option('-t', help="The type you want to monitor (inlet, outlet, sensor)", default="inlet", dest="typ") 28 | helper.parser.add_option('-i', help="The id of the outlet / sensor you want to monitor (1-99)", default="1", dest="id") 29 | helper.parse_arguments() 30 | 31 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 32 | 33 | # The default return value should be always OK 34 | helper.status(ok) 35 | 36 | raritan = health_monitoring_plugins.raritan.Raritan(sess, helper.options.id) 37 | device_type = helper.options.typ.lower() 38 | if device_type == "inlet": 39 | raritan.check_inlet(helper) 40 | elif device_type == "outlet": 41 | raritan.check_outlet(helper) 42 | elif device_type == "sensor": 43 | raritan.check_sensor(helper) 44 | 45 | helper.exit() 46 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # check_snmp_s650.py - Monitor a Microsemi S650 Timeserver 4 | 5 | # Copyright (C) 2017-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | # based on the S650ALARM.mib 23 | 24 | import sys 25 | import os 26 | import netsnmp 27 | sys.path.insert(1, os.path.join(sys.path[0], os.pardir)) 28 | from snmpSessionBaseClass import add_common_options, get_common_options, verify_host, get_data 29 | from pynag.Plugins import PluginHelper,ok,warning,critical,unknown 30 | 31 | # Create an instance of PluginHelper() 32 | helper = PluginHelper() 33 | 34 | # Define the command line options 35 | add_common_options(helper) 36 | helper.parser.add_option('-U', '--unit', dest='unit', help='Select the unit you want to monitor, if no unit is selected both units will be monitored', default="1") 37 | helper.parse_arguments() 38 | 39 | # get the options 40 | host, version, community = get_common_options(helper) 41 | unit = helper.options.unit 42 | 43 | # OIDs from S650ALARM.mib 44 | unit1_oid = "iso.1.3.6.1.4.1.31210.52.1.9.0" 45 | unit2_oid = "iso.1.3.6.1.4.1.31210.52.1.13.0" 46 | 47 | status = { 48 | "0" : "Online", 49 | "1" : "Standby", 50 | "2" : "Alarmed" 51 | } 52 | 53 | if __name__ == "__main__": 54 | 55 | # verify that a hostname is set 56 | verify_host(host, helper) 57 | 58 | # The default return value should be always OK 59 | helper.status(ok) 60 | 61 | sess = netsnmp.Session(Version=version, DestHost=host, Community=community) 62 | 63 | # get the values 64 | if unit == "1": 65 | value = get_data(sess, unit1_oid, helper) 66 | elif unit == "2": 67 | value = get_data(sess, unit2_oid, helper) 68 | else: 69 | helper.exit(summary="Wrong unit specified", exit_code=unknown, perfdata='') 70 | 71 | 72 | # add the summary 73 | helper.add_summary("Unit status is: %s" % (status[value])) 74 | 75 | if value == "2": 76 | helper.status(critical) 77 | 78 | # Print out plugin information and exit nagios-style 79 | helper.exit() 80 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_service/check_snmp_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # check_snmp_service.py - Check if a Windows service is in running state via SNMP. 3 | 4 | # Copyright (C) 2017-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | # Import PluginHelper and some utility constants from the Plugins module 22 | 23 | from __future__ import absolute_import, division, print_function 24 | from pynag.Plugins import ok 25 | import health_monitoring_plugins.windowsservice 26 | 27 | if __name__ == '__main__': 28 | # pylint: disable=C0103 29 | helper = health_monitoring_plugins.SnmpHelper() 30 | 31 | helper.parser.add_option('-s', '--service', 32 | help="The name of the service you want to monitor " 33 | "(-s scan for scanning)", 34 | dest="service", default='') 35 | helper.parser.add_option('-S', '--scan', dest='scan_flag', default=False, action="store_true", 36 | help='Show all available services') 37 | 38 | helper.parse_arguments() 39 | 40 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 41 | 42 | # The default return value should be always OK 43 | helper.status(ok) 44 | 45 | windowsservice = health_monitoring_plugins.windowsservice.Windowsservice(sess) 46 | 47 | # if no service is set, we will do a scan; or if scan_flag is set 48 | if helper.options.service == "" or \ 49 | helper.options.service is None or \ 50 | helper.options.scan_flag: 51 | # Device information 52 | # run_scan() 53 | windowsservice.run_scan(helper, sess) 54 | 55 | else: 56 | windowsservice.check_service(helper, sess) 57 | 58 | # Print out plugin information and exit nagios-style 59 | helper.exit() 60 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_teledyne/check_snmp_teledyne.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # check_snmp_teledyne.py - Monitor the health status of Teledyne Paradise Datacom 3 | 4 | # Copyright (C) 2017-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | # Import PluginHelper and some utility constants from the Plugins module 22 | import sys 23 | import os 24 | import netsnmp 25 | sys.path.insert(1, os.path.join(sys.path[0], os.pardir)) 26 | from snmpSessionBaseClass import add_common_options, get_common_options, verify_host, get_data 27 | from pynag.Plugins import PluginHelper,ok,critical 28 | 29 | 30 | # Create an instance of PluginHelper() 31 | helper = PluginHelper() 32 | 33 | # add the common command line options 34 | add_common_options(helper) 35 | helper.parse_arguments() 36 | 37 | # get the options 38 | host, version, community = get_common_options(helper) 39 | 40 | 41 | # OIDs from MBG-LANTIME-NG-MIB.mib 42 | oids = { 43 | "Unit 1" : "iso.3.6.1.4.1.20712.2.1.3.1.2.1", 44 | "Unit 2" : "iso.3.6.1.4.1.20712.2.1.3.1.2.2", 45 | "Unit 3" : "iso.3.6.1.4.1.20712.2.1.3.1.2.3", 46 | "Fault Summary" : "iso.3.6.1.4.1.20712.2.1.3.1.2.4", 47 | "Power Supply 1" : "iso.3.6.1.4.1.20712.2.1.3.1.2.5", 48 | "Power Supply 2" : "iso.3.6.1.4.1.20712.2.1.3.1.2.6", 49 | "RF Switch 1" : "iso.3.6.1.4.1.20712.2.1.3.1.2.11", 50 | "RF Switch 2" : "iso.3.6.1.4.1.20712.2.1.3.1.2.12" 51 | } 52 | 53 | status = { 54 | "0" : "No Fault", 55 | "1" : "Fault", 56 | "2" : "N/A", 57 | "3" : "Pos1", 58 | "4" : "Pos2" 59 | } 60 | 61 | if __name__ == "__main__": 62 | 63 | # verify that a hostname is set 64 | verify_host(host, helper) 65 | 66 | # The default return value should be always OK 67 | helper.status(ok) 68 | 69 | sess = netsnmp.Session(Version=version, DestHost=host, Community=community) 70 | 71 | # here we check the status 72 | for name in sorted(oids): 73 | 74 | # get the snmp values 75 | value = get_data(sess, oids[name], helper) 76 | 77 | helper.add_summary("%s: %s" % (name, status[value])) 78 | 79 | # if the value is 1 / Fault the status is set to critical 80 | if value == "1": 81 | helper.status(critical) 82 | 83 | # Print out plugin information and exit nagios-style 84 | helper.exit() 85 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_time2/check_snmp_time2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # check_snmp_time2.py - Check 3 | 4 | # Copyright (C) 2016 Retakfual 5 | # 2016-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | 23 | from __future__ import absolute_import, division, print_function 24 | from pynag.Plugins import ok 25 | import health_monitoring_plugins.timesource 26 | 27 | if __name__ == '__main__': 28 | # pylint: disable=C0103 29 | helper = health_monitoring_plugins.SnmpHelper() 30 | 31 | helper.parser.add_option('-o', '--tzoffset', dest='tzoffset', 32 | default=0, type='int', 33 | help='the local systems utc offset to the servers utc, in minutes (' 34 | 'use only if your remote device is in a different timezone)') 35 | 36 | helper.parser.add_option('-l', '--localtime', dest='time_flag', 37 | default=False, action="store_true", 38 | help='force to use local time (only recommended if you have a non ' 39 | 'Windows OS remote device, that returns localtime and not utc)') 40 | 41 | helper.parse_arguments() 42 | 43 | sess = health_monitoring_plugins.SnmpSession(**helper.get_snmp_args()) 44 | 45 | # The default return value should be always OK 46 | helper.status(ok) 47 | 48 | timesource = health_monitoring_plugins.timesource.Timesource(sess) 49 | 50 | timesource.check_time(helper, sess) 51 | 52 | helper.check_all_metrics() 53 | helper.exit() 54 | 55 | -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # check_snmp_trusted_filter.py - Check a trusted filter 3 | 4 | # Copyright (C) 2017-2019 rsmuc 5 | 6 | # This file is part of "Health Monitoring Plugins". 7 | 8 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 2 of the License, or 11 | # (at your option) any later version. 12 | 13 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with "Health Monitoring Plugins". If not, see . 20 | 21 | import netsnmp 22 | import pynag.Plugins 23 | import health_monitoring_plugins.trustedfilter 24 | 25 | if __name__ == "__main__": 26 | helper = health_monitoring_plugins.SnmpHelper() 27 | helper.parser.add_option('-s', '--secondhost', dest='secondhost', type='str', 28 | help = "Enter a second host to be checked for ActivityState") 29 | helper.parse_arguments() 30 | helper.status(pynag.Plugins.ok) 31 | 32 | snmp_args = helper.get_snmp_args() 33 | snmp1 = health_monitoring_plugins.SnmpSession(**snmp_args) 34 | if helper.options.secondhost: 35 | snmp_args['DestHost'] = helper.options.secondhost 36 | snmp2 = health_monitoring_plugins.SnmpSession(**snmp_args) 37 | else: 38 | snmp2 = None 39 | 40 | trustedFilter = health_monitoring_plugins.trustedfilter.TrustedFilter(helper, snmp1, snmp2) 41 | trustedFilter.check() 42 | 43 | helper.exit() -------------------------------------------------------------------------------- /health_monitoring_plugins/check_snmp_ubiquiti/check_snmp_ubiquiti.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # check_snmp_ubiquiti.py - Monitor a Ubiquity airMax. 4 | 5 | # Copyright (C) 2016 Retakfual 6 | # 2016-2019 rsmuc 7 | 8 | # This file is part of "Health Monitoring Plugins". 9 | 10 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation, either version 2 of the License, or 13 | # (at your option) any later version. 14 | 15 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | 20 | # You should have received a copy of the GNU General Public License 21 | # along with "Health Monitoring Plugins". If not, see . 22 | 23 | # Imports 24 | from pynag.Plugins import PluginHelper,ok,warning,critical,unknown 25 | import commands, sys, argparse, math 26 | import netsnmp 27 | import os 28 | import datetime 29 | sys.path.insert(1, os.path.join(sys.path[0], os.pardir)) 30 | from snmpSessionBaseClass import add_common_options, get_common_options, verify_host, get_data 31 | 32 | # Create an instance of PluginHelper() 33 | helper = PluginHelper() 34 | 35 | # Define the command line options 36 | add_common_options(helper) 37 | helper.parser.add_option('-t', '--type', dest='power_Status', help='Select a Type, for a list of all possible Types use the argument -l') 38 | helper.parser.add_option('-l', '--list', dest='listFlag', default='False', action='store_true', help='Lists all output possibilities') 39 | helper.parse_arguments() 40 | 41 | status = helper.options.power_Status 42 | flag_list = helper.options.listFlag 43 | host, version, community = get_common_options(helper) 44 | 45 | 46 | names = ["up", "signal", "cpu1m", "cpu5m", "cpu15m", "totalmem", "freemem", "tx", "rx"] 47 | 48 | descriptions=["Uptime", "Signal Strength", "CPU usage (1 Minute Average)", "CPU usage (5 Minute Average)", 49 | "CPU usage (15 Minute Average)", "Total memory", "Free memory", "Tx Rate", "Rx Rate" ] 50 | 51 | oids=[".1.3.6.1.2.1.1.3.0", ".1.3.6.1.4.1.14988.1.1.1.1.1.4", ".1.3.6.1.4.1.10002.1.1.1.4.2.1.3.1", 52 | ".1.3.6.1.4.1.10002.1.1.1.4.2.1.3.2",".1.3.6.1.4.1.10002.1.1.1.4.2.1.3.3",".1.3.6.1.4.1.10002.1.1.1.1.1.0", 53 | ".1.3.6.1.4.1.10002.1.1.1.1.2.0",".1.3.6.1.4.1.14988.1.1.1.1.1.2",".1.3.6.1.4.1.14988.1.1.1.1.1.3"] 54 | 55 | units =['', '', '', '%', '%', '%', '', 'Byte', '', '' ] 56 | 57 | 58 | ############## 59 | ## Main ## 60 | ############### 61 | if __name__ == '__main__': 62 | # The default return value should be always OK 63 | helper.status(ok) 64 | 65 | # shows the list of possible types if the flag is set 66 | if flag_list == True: 67 | for w,v in zip(names, descriptions): 68 | print w + ' = ' + v 69 | helper.status(unknown) 70 | helper.exit(summary='This is just a list and not a check!') 71 | 72 | # verify that a hostname is set 73 | verify_host(host, helper) 74 | 75 | # open session after validated host 76 | sess = netsnmp.Session(Version=version, DestHost=host, Community=community) 77 | 78 | # verify, that status(/type) parameter is not empty 79 | if (status == None) or (status not in names): 80 | helper.status(unknown) 81 | helper.exit(summary='Argument -t is missing or false!') 82 | 83 | # snmp gets for all oids in type-list 84 | ind = names.index(status) 85 | value = get_data(sess, oids[ind],helper) 86 | 87 | if names.index(status) == 0: 88 | value = str(datetime.timedelta(seconds=int(value))) 89 | helper.exit(summary='Uptime = %s'%value) 90 | 91 | # metric compares 92 | helper.add_metric(label='type', value = value, uom =' '+units[ind]+' ') 93 | helper.check_all_metrics() 94 | 95 | # programm end 96 | helper.exit() 97 | -------------------------------------------------------------------------------- /health_monitoring_plugins/eps_plus.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module for check_snmp_eps_plus.py 3 | """ 4 | 5 | # Copyright (C) 2016-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | from __future__ import absolute_import, division, print_function 23 | from pynag.Plugins import critical, unknown 24 | 25 | # that is the base oid 26 | DEVICE_NAME_OID = ".1.3.6.1.4.1.24734.16.2.1.1.3" 27 | OUTLET_NAME_OID = ".1.3.6.1.4.1.24734.16.8.1.1.4" 28 | OUTLET_STATUS_OID = ".1.3.6.1.4.1.24734.16.8.1.1.5" 29 | SENSOR_ID_OID = ".1.3.6.1.4.1.24734.16.5.1.1.3" 30 | SENSOR_VALUE_OID = ".1.3.6.1.4.1.24734.16.5.1.1.6" 31 | 32 | 33 | class EPSplus(object): 34 | """EpowerSwitch""" 35 | 36 | @staticmethod 37 | def get_outlet_info(helper, session): 38 | """ get the infos for the outlet """ 39 | 40 | device_name_oid = "{}.{}".format(DEVICE_NAME_OID, helper.options.device) 41 | outlet_name_oid = "{}.{}.{}".format(OUTLET_NAME_OID, 42 | helper.options.device, helper.options.outlet) 43 | outlet_status_oid = "{}.{}.{}".format(OUTLET_STATUS_OID, 44 | helper.options.device, helper.options.outlet) 45 | 46 | return helper.get_snmp_values_or_exit(session, helper, 47 | device_name_oid, outlet_name_oid, outlet_status_oid) 48 | 49 | @staticmethod 50 | def get_sensor_info(helper, session): 51 | """ get the infos for the outlet """ 52 | 53 | sensor_ids = helper.walk_snmp_values_or_exit(session, helper, 54 | SENSOR_ID_OID, "Sensor IDs") 55 | sensor_values = helper.walk_snmp_values_or_exit(session, helper, 56 | SENSOR_VALUE_OID, "Sensor Values") 57 | 58 | values = zip(sensor_ids, sensor_values) 59 | 60 | for entry in values: 61 | sid = entry[0] 62 | value = entry[1] 63 | unit = None 64 | name = None 65 | 66 | if "T" in sid: 67 | unit = "deg. C" 68 | name = "temperature sensor" 69 | elif "H" in sid: 70 | unit = "percent" 71 | name = "humidity sensor" 72 | 73 | if sid == helper.options.sensor: 74 | return name, value, unit 75 | 76 | helper.exit(summary="Sensor not found", exit_code=unknown, perfdata='') 77 | return None 78 | 79 | def check_outlet(self, helper, session): 80 | """ 81 | check the status of an outlet (on, off) 82 | """ 83 | 84 | infos = self.get_outlet_info(helper, session) 85 | 86 | device_name = infos[0] 87 | outlet_name = infos[1] 88 | outlet_status = infos[2] 89 | 90 | helper.add_summary("{} - {}: {}".format(device_name, outlet_name, outlet_status)) 91 | 92 | if outlet_status != helper.options.expected: 93 | helper.status(critical) 94 | 95 | def check_sensor(self, helper, session): 96 | """ 97 | check the value of an sensor 98 | """ 99 | 100 | infos = self.get_sensor_info(helper, session) 101 | 102 | sensor_name = infos[0] 103 | sensor_value = infos[1] 104 | sensor_unit = infos[2] 105 | 106 | helper.add_summary("{}: {} {}".format(sensor_name, sensor_value, sensor_unit)) 107 | helper.add_metric("{} (in {})".format(sensor_name, sensor_unit).lower(), 108 | sensor_value, "", "", "", "", "") 109 | -------------------------------------------------------------------------------- /health_monitoring_plugins/inradios_csm.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 - 2019 haxtibal 2 | 3 | # This file is part of "Health Monitoring Plugins". 4 | 5 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 2 of the License, or 8 | # (at your option) any later version. 9 | 10 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | # You should have received a copy of the GNU General Public License 16 | # along with "Health Monitoring Plugins". If not, see . 17 | 18 | import netsnmp 19 | import pynag.Plugins 20 | 21 | class InradiosCsmHealth(object): 22 | csm_to_icinga_status = { 23 | 0: pynag.Plugins.unknown, 24 | 1: pynag.Plugins.unknown, 25 | 2: pynag.Plugins.ok, 26 | 3: pynag.Plugins.warning, 27 | 4: pynag.Plugins.critical 28 | } 29 | 30 | csm_to_str = ("Not ready", "Not available", "OK", "Warning", "Alarm") 31 | 32 | def __init__(self, snmp_session, meas_id): 33 | self.snmp_session = snmp_session 34 | self.meas_id = meas_id 35 | 36 | def make_meas_varlist(self): 37 | oid_list = [netsnmp.Varbind('.1.3.6.1.4.1.2566.127.6.1.10.1.1.1.{}.{}' 38 | .format(x, self.meas_id)) for x in range(1, 12)] 39 | return netsnmp.VarList(*oid_list) 40 | 41 | def check(self): 42 | try: 43 | self.snmp_data = self.get_data() 44 | except (TypeError, KeyError, ValueError): 45 | self.snmp_data = None 46 | 47 | def get_data(self): 48 | varlist = self.make_meas_varlist() 49 | response = self.snmp_session.get(varlist) 50 | snmp_data = { 51 | 'comment': str(response[0]), 52 | 'value': float(response[1]) if response[1] else None, 53 | 'valueDateTime': str(response[2]) if response[2] else None, 54 | 'parameter': str(response[3]), 55 | 'status': int(response[4]), 56 | 'uom': str(response[5]) if response[5] else None, 57 | 'warn_upper': float(response[6]), 58 | 'alarm_upper': float(response[7]), 59 | 'warn_lower': float(response[8]), 60 | 'alarm_lower': float(response[9]), 61 | 'label': str(response[10]) if response[10] else "Measurement ID {}".format(self.meas_id) 62 | } 63 | return snmp_data 64 | 65 | def feed_icinga_plugin(self, icinga_plugin): 66 | if not self.snmp_data: 67 | icinga_plugin.show_status_in_summary = True 68 | icinga_plugin.status(pynag.Plugins.unknown) 69 | icinga_plugin.add_summary("SNMP response incomplete or invalid") 70 | return 71 | icinga_plugin.show_status_in_summary = False 72 | icinga_plugin.status(self.csm_to_icinga_status[self.snmp_data['status']]) 73 | icinga_plugin.add_summary(self.make_summary()) 74 | for prm_info in self.make_prm_info(): 75 | icinga_plugin.add_long_output(prm_info) 76 | if self.snmp_data['value']: 77 | icinga_plugin.add_metric(**self.make_metric()) 78 | 79 | def make_summary(self): 80 | summary_fmt = "{} - {} ({})" 81 | return summary_fmt.format(self.csm_to_str[self.snmp_data['status']], 82 | self.make_value_str(), self.make_clock_str()) 83 | 84 | def make_clock_str(self): 85 | date_time = "last update: {}" 86 | if self.snmp_data['valueDateTime']: 87 | return date_time.format(self.snmp_data['valueDateTime'].split(' ')[-1]) 88 | else: 89 | return date_time.format("n/a") 90 | 91 | def make_value_str(self): 92 | value_str = self.snmp_data['label'] 93 | if self.snmp_data['value']: 94 | value_str += ' = ' + str(self.snmp_data['value']) 95 | if self.snmp_data['uom']: 96 | value_str += ' ' + self.snmp_data['uom'] 97 | else: 98 | value_str += ' = n/a' 99 | return value_str 100 | 101 | def make_prm_info(self): 102 | prm_info = [] 103 | for prm in self.snmp_data['parameter'].split(';'): 104 | if prm: 105 | prm_info.append(prm.strip()) 106 | if self.snmp_data['valueDateTime']: 107 | prm_info.append("Last update: " + self.snmp_data['valueDateTime']) 108 | return prm_info 109 | 110 | def make_metric(self): 111 | metric = {'label': self.snmp_data['label'], 112 | 'value': self.snmp_data['value']} 113 | if self.snmp_data['uom']: 114 | metric['uom'] = self.snmp_data['uom'] 115 | warn = self.format_perfdata(self.snmp_data.get('warn_lower'), self.snmp_data.get('warn_upper')) 116 | crit = self.format_perfdata(self.snmp_data.get('alarm_lower'), self.snmp_data.get('alarm_upper')) 117 | if warn: 118 | metric['warn'] = warn 119 | if crit: 120 | metric['crit'] = crit 121 | return metric 122 | 123 | def format_perfdata(self, lower, upper): 124 | neg_inf = float('-inf') 125 | pos_inf = float('inf') 126 | # NaN can be tested by testing equality to itself 127 | if not lower or lower != lower: 128 | lower = neg_inf 129 | if not upper or upper != upper: 130 | upper = pos_inf 131 | if lower == neg_inf and upper == pos_inf: 132 | return None 133 | return "{:.7g}..{:.7g}".format(lower, upper) 134 | -------------------------------------------------------------------------------- /health_monitoring_plugins/ipport.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module for check_snmp_port.py 3 | """ 4 | 5 | # Copyright (C) 2016-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | from __future__ import absolute_import, division, print_function 23 | from pynag.Plugins import critical, ok, unknown, warning 24 | 25 | # that is the base oid 26 | OPEN_UDP_PORTS_OID = ".1.3.6.1.2.1.7.5.1.2" 27 | TCP_PORTS_OID = ".1.3.6.1.2.1.6.13.1.3" 28 | TCP_PORTS_STATUS_OID = ".1.3.6.1.2.1.6.13.1.1" 29 | 30 | # from tcpConnState from TCP-MIB 31 | TCP_STATES = { 32 | "1": "closed", 33 | "2": "listen", 34 | "3": "synSent", 35 | "4": "synReceived", 36 | "5": "established", 37 | "6": "finWait1", 38 | "7": "finWait2", 39 | "8": "closeWait", 40 | "9": "lastAck", 41 | "10": "closing", 42 | "11": "timeWait", 43 | "12": "deleteTCB" 44 | } 45 | 46 | 47 | class Port(object): 48 | """Class for check_snmp_port""" 49 | 50 | def __init__(self, session): 51 | self.sess = session 52 | 53 | @staticmethod 54 | def check_port(helper): 55 | """ 56 | check if the port parameter is really a port or "scan" 57 | """ 58 | try: 59 | int(helper.options.port) 60 | except ValueError: 61 | helper.exit(summary="Port (-p) must be a integer value.", exit_code=unknown, 62 | perfdata='') 63 | 64 | @staticmethod 65 | def get_open_udp_ports(helper, session): 66 | """ get the open UDP ports """ 67 | open_ports = helper.walk_snmp_values_or_exit(session, helper, 68 | OPEN_UDP_PORTS_OID, "Open UDP Ports") 69 | return open_ports 70 | 71 | @staticmethod 72 | def get_open_tcp_ports(helper, session): 73 | """ get the open tcp ports and the status""" 74 | open_ports = helper.walk_snmp_values_or_exit(session, helper, 75 | TCP_PORTS_OID, "Open TCP Ports") 76 | port_status = helper.walk_snmp_values_or_exit(session, helper, 77 | TCP_PORTS_STATUS_OID, "Port Status") 78 | 79 | return open_ports, port_status 80 | 81 | def run_scan(self, helper, session): 82 | """ 83 | show all open ports 84 | """ 85 | 86 | # UDP ports 87 | print("All open UDP ports at host " + helper.options.hostname) 88 | for port in self.get_open_udp_ports(helper, session): 89 | print("UDP: \t" + port) 90 | 91 | # TCP ports 92 | # make a dict out of the two lists (ports & status) 93 | ports_and_status = dict(zip(self.get_open_tcp_ports(helper, session)[0], 94 | self.get_open_tcp_ports(helper, session)[1])) 95 | 96 | # here we show all open TCP ports and it's status 97 | print ("\n\n\nAll open TCP ports at host " + helper.options.hostname) 98 | 99 | for port in ports_and_status: 100 | tcp_status = ports_and_status[port] 101 | tcp_status = TCP_STATES[tcp_status] 102 | print("TCP: \t" + port + "\t Status: \t" + tcp_status) 103 | 104 | quit() 105 | 106 | def check_udp(self, helper, session): 107 | """ 108 | check the status of the UDP ports 109 | """ 110 | open_ports = self.get_open_udp_ports(helper, session) 111 | 112 | if helper.options.port in open_ports: 113 | udp_status = "OPEN" 114 | 115 | else: 116 | udp_status = "CLOSED" 117 | helper.status(critical) 118 | 119 | helper.add_summary("Current status for UDP port " 120 | + helper.options.port 121 | + " is: " 122 | + udp_status) 123 | 124 | def check_tcp(self, helper, session): 125 | """ 126 | check the status of the TCP ports 127 | """ 128 | 129 | open_ports = self.get_open_tcp_ports(helper, session)[0] 130 | port_states = self.get_open_tcp_ports(helper, session)[1] 131 | 132 | ports_and_states = dict(zip(open_ports, port_states)) 133 | 134 | if helper.options.port in open_ports: 135 | 136 | # if the port is available in the list of open_ports, then extract the status 137 | tcp_status = ports_and_states[helper.options.port] 138 | 139 | # translate the status from the integer value to a human readable string 140 | tcp_status = TCP_STATES[tcp_status] 141 | 142 | # now let's set the status according to the warning / critical "threshold" parameter 143 | if tcp_status in helper.options.warning: 144 | helper.status(warning) 145 | 146 | elif tcp_status in helper.options.critical: 147 | helper.status(critical) 148 | 149 | else: 150 | helper.status(ok) 151 | else: 152 | # if there is no value in the list => the port is closed for sure 153 | tcp_status = "CLOSED" 154 | helper.status(critical) 155 | 156 | helper.add_summary("Current status for TCP port " 157 | + helper.options.port 158 | + " is: " 159 | + tcp_status) 160 | -------------------------------------------------------------------------------- /health_monitoring_plugins/plugin_rules.md: -------------------------------------------------------------------------------- 1 | # Some general rules for our plugins (DRAFT) 2 | 3 | * UOMs: The units of the metrics are not written in the UOM field. We write them in the label. 4 | The offical supported UOMs are too limites 5 | 6 | * Each status that is processes, will be written to the long output if it is ok. If it is not OK, we 7 | will write it to the summary 8 | 9 | * Plugins will process all checks with one call. So we need usually only one service per monitored 10 | device. Except if the plugin will be used to execute event handlers. Then every check that 11 | will be done, will result in a single service. e.g. for Eaton UPS. -------------------------------------------------------------------------------- /health_monitoring_plugins/procurve.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module for check_snmp_procurve 3 | """ 4 | 5 | # Copyright (C) 2016-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | from __future__ import absolute_import, division, print_function 23 | from pynag.Plugins import unknown, critical, warning 24 | 25 | 26 | # required OIDS 27 | # The sensor description (e.g. Power Supply Sensor or Fan Sensor) 28 | OID_DESCRIPTION = ".1.3.6.1.4.1.11.2.14.11.1.2.6.1.7" 29 | # The status of the sensor 30 | OID_STATUS = ".1.3.6.1.4.1.11.2.14.11.1.2.6.1.4" 31 | 32 | 33 | # Sensor Status table 34 | SENOR_STATUS_TABLE = { 35 | "1": "unknown", 36 | "2": "bad", 37 | "3": "warning", 38 | "4": "good", 39 | "5": "notPresent" 40 | } 41 | 42 | 43 | class Procurve(object): 44 | """Class for check_snmp_time2""" 45 | 46 | def __init__(self, session): 47 | self.sess = session 48 | 49 | @staticmethod 50 | def check_sensors(helper, session): 51 | """ 52 | collect and check all available sensors 53 | """ 54 | 55 | all_sensors = helper.walk_snmp_values_or_exit(session, helper, OID_DESCRIPTION, "Sensors") 56 | all_status = helper.walk_snmp_values_or_exit(session, helper, OID_STATUS, "Sensor Status") 57 | 58 | # here we zip all index and descriptions to have a list like 59 | # [('Fan Sensor', '2'), ('Power Supply Sensor', '4')] 60 | # we are doomed if the lists do not have the same length ... 61 | # but that should never happen ... hopefully 62 | zipped = zip(all_sensors, all_status) 63 | 64 | for sensor in zipped: 65 | description = sensor[0] 66 | status = sensor[1] 67 | # translate the value to human readable 68 | try: 69 | status_string = SENOR_STATUS_TABLE[status] 70 | except KeyError: 71 | # if we receive an invalid value, we don't want to crash... 72 | helper.exit(summary="received an undefined value from device: " + status, 73 | exit_code=critical, perfdata='') 74 | 75 | # for each sensor the summary is added like: Fan Sensor: good 76 | helper.add_summary("%s: %s" % (description, status_string)) 77 | 78 | # set the status 79 | if status == "2": 80 | helper.status(critical) 81 | if status == "3": 82 | helper.status(warning) 83 | -------------------------------------------------------------------------------- /health_monitoring_plugins/trustedfilter.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017-2019 rsmuc 2 | 3 | # This file is part of "Health Monitoring Plugins". 4 | 5 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 2 of the License, or 8 | # (at your option) any later version. 9 | 10 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | # You should have received a copy of the GNU General Public License 16 | # along with "Health Monitoring Plugins". If not, see . 17 | 18 | from pynag.Plugins import PluginHelper,ok,warning,critical,unknown 19 | import health_monitoring_plugins 20 | 21 | # these dicts / definitions we need to get human readable values 22 | states = { 23 | 1: 'ok', 24 | 2: 'failed', 25 | 3: 'absent', 26 | 4: 'AC off' 27 | } 28 | 29 | activity = { 30 | 1: 'standby', 31 | 2: 'active', 32 | 3: 'error' 33 | } 34 | 35 | # OIDs 36 | activity_oid = '.1.3.6.1.4.1.2566.107.41.1.0' # tfDeviceActivityState 37 | logfill_oid = '.1.3.6.1.4.1.2566.107.31.2.1.0' # slIpStatusLogFillLevel 38 | ps1_oid = '.1.3.6.1.4.1.2566.107.31.2.2.0' # slIpStatusPowerSupplyUnit1 39 | ps2_oid = '.1.3.6.1.4.1.2566.107.31.2.3.0' # slIpStatusPowerSupplyUnit2 40 | fan1_oid = '.1.3.6.1.4.1.2566.107.31.2.4.0' # slIpStatusPowerFanUnit1 41 | fan2_oid = '.1.3.6.1.4.1.2566.107.31.2.5.0' # slIpStatusPowerFanUnit2 42 | bat_oid = '.1.3.6.1.4.1.2566.107.31.2.7.0' # slIpStatusInternalVoltage 43 | temp_oid = '.1.3.6.1.4.1.2566.107.31.2.8.0' # slIpStatusInternalTemperature 44 | activity_oid = '.1.3.6.1.4.1.2566.107.41.1.0' # tfDeviceActivityState 45 | 46 | 47 | class TrustedFilter(object): 48 | def __init__(self, helper, snmp1, snmp2=None): 49 | self.helper = helper 50 | self.snmp1 = snmp1 51 | self.snmp2 = snmp2 52 | 53 | def get_snmp_from_host1(self): 54 | """ 55 | Get SNMP values from 1st host. 56 | """ 57 | response = self.snmp1.get_oids(ps1_oid, ps2_oid, fan1_oid, fan2_oid, bat_oid, temp_oid, activity_oid, logfill_oid) 58 | self.ps1_value = states[int(response[0])] 59 | self.ps2_value = states[int(response[1])] 60 | self.fan1_value = states[int(response[2])] 61 | self.fan2_value = states[int(response[3])] 62 | self.bat_value = states[int(response[4])] 63 | self.temp_value = states[int(response[5])] 64 | self.activity_value1 = activity[int(response[6])] 65 | self.logfill_value = str(response[7]) 66 | 67 | def get_snmp_from_host2(self): 68 | """ 69 | Get SNMP values from 2nd host. 70 | """ 71 | if not self.snmp2: 72 | self.activity_value2 = None 73 | else: 74 | response = self.snmp2.get_oids(activity_oid) 75 | self.activity_value2 = activity[int(response[0])] 76 | 77 | def check(self): 78 | """ 79 | Evaluate health status from device parameters. 80 | """ 81 | try: 82 | self.get_snmp_from_host1() 83 | self.get_snmp_from_host2() 84 | except (health_monitoring_plugins.SnmpException, TypeError, KeyError): 85 | self.helper.status(unknown) 86 | self.helper.add_summary("SNMP response incomplete or invalid") 87 | return 88 | 89 | self.helper.add_summary("Filter Status") 90 | self.helper.add_long_output("Power Supply 1: %s" % self.ps1_value) 91 | if self.ps1_value != "ok": 92 | self.helper.status(critical) 93 | self.helper.add_summary("Power Supply 1: %s" % self.ps1_value) 94 | 95 | self.helper.add_long_output("Power Supply 2: %s" % self.ps2_value) 96 | if self.ps2_value != "ok": 97 | self.helper.status(critical) 98 | self.helper.add_summary("Power Supply 2: %s" % self.ps2_value) 99 | 100 | self.helper.add_long_output("Fan 1: %s" % self.fan1_value) 101 | if self.fan1_value != "ok": 102 | self.helper.status(critical) 103 | self.helper.add_summary("Fan 1: %s" % self.fan1_value) 104 | 105 | self.helper.add_long_output("Fan 2: %s" % self.fan2_value) 106 | if self.fan2_value != "ok": 107 | self.helper.status(critical) 108 | self.helper.add_summary("Fan 2: %s" % self.fan2_value) 109 | 110 | self.helper.add_long_output("Battery: %s" % self.bat_value) 111 | if self.bat_value != "ok": 112 | self.helper.status(critical) 113 | self.helper.add_summary("Battery: %s" % self.bat_value) 114 | 115 | self.helper.add_long_output("Temperature: %s" % self.temp_value) 116 | if self.temp_value != "ok": 117 | self.helper.status(critical) 118 | self.helper.add_summary("Temperature: %s" % self.temp_value) 119 | 120 | self.helper.add_metric(label='logfill',value=self.logfill_value, uom="%%") 121 | self.helper.add_long_output("Fill Level internal log: %s%%" % self.logfill_value) 122 | 123 | self.helper.add_long_output("Activity State: %s" % self.activity_value1) 124 | if self.activity_value1 == "error": 125 | self.helper.status(critical) 126 | self.helper.add_summary("Activity State: %s" % self.activity_value1) 127 | 128 | if self.activity_value2: 129 | self.helper.add_long_output("Activity State 2: %s" % self.activity_value2) 130 | if self.activity_value1 == "active" and self.activity_value2 == "active": 131 | self.helper.status(critical) 132 | self.helper.add_summary("Filter 1 and Filter 2 active!") 133 | 134 | if self.activity_value1 == "standby" and self.activity_value2 == "standby": 135 | self.helper.status(critical) 136 | self.helper.add_summary("Filter 1 and Filter 2 standby!") 137 | 138 | self.helper.check_all_metrics() 139 | -------------------------------------------------------------------------------- /health_monitoring_plugins/windowsservice.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module for check_snmp_service.py 3 | """ 4 | 5 | # Copyright (C) 2016-2019 rsmuc 6 | 7 | # This file is part of "Health Monitoring Plugins". 8 | 9 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 2 of the License, or 12 | # (at your option) any later version. 13 | 14 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with "Health Monitoring Plugins". If not, see . 21 | 22 | from __future__ import absolute_import, division, print_function 23 | from pynag.Plugins import critical, ok 24 | 25 | # that is the base oid 26 | BASE_OID = ".1.3.6.1.4.1.77.1.2.3.1.1" 27 | 28 | 29 | def convert_in_oid(service_name): 30 | """ 31 | calculate the correct OID for the service name 32 | """ 33 | # convert the service_name to ascci 34 | service_ascii = [ord(c) for c in service_name] 35 | # we need the length of the service name 36 | length = str(len(service_name)) 37 | # make the oid 38 | oid = BASE_OID + "." + length + "." + ".".join(str(x) for x in service_ascii) 39 | return oid 40 | 41 | 42 | class Windowsservice(object): 43 | """Class for check_snmp_service""" 44 | 45 | def __init__(self, session): 46 | self.sess = session 47 | 48 | @staticmethod 49 | def run_scan(helper, session): 50 | """ 51 | show all available services 52 | """ 53 | 54 | all_services = helper.walk_snmp_values_or_exit(session, helper, BASE_OID, "Service Scan") 55 | 56 | print("Running services at host: " + helper.options.hostname) 57 | 58 | for service in all_services: 59 | print("Service: \t'" + service + "'") 60 | 61 | # we don't want to return a icinga output, so we just end the script here 62 | quit() 63 | 64 | @staticmethod 65 | def check_service(helper, session): 66 | """ 67 | check the defined services 68 | """ 69 | 70 | # convert the service name to a oid 71 | service_oid = convert_in_oid(helper.options.service) 72 | result = session.get_oids(service_oid)[0] 73 | 74 | if not result or result == "NOSUCHOBJECT": 75 | service_status = "NOT RUNNING" 76 | helper.status(critical) 77 | else: 78 | service_status = "RUNNING" 79 | helper.status(ok) 80 | 81 | helper.add_summary("Status of Service '" + helper.options.service + "' is: " 82 | + service_status) 83 | -------------------------------------------------------------------------------- /icingaexchange.yml: -------------------------------------------------------------------------------- 1 | name: health_monitoring_plugins 2 | description: "file:///README.md" 3 | url: "https://github.com/rsmuc/health_monitoring_plugins" 4 | tags: SNMP, Monitoring, Package 5 | vendor: Icinga 6 | target: Operating System, Environmental, Hardware, NTP, SNMP, Sensor, Time 7 | type: Plugin 8 | license: gplv2 -------------------------------------------------------------------------------- /run_unittest.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | # Copyright (C) 2016-2019 rsmuc 4 | 5 | # This file is part of "Health Monitoring Plugins". 6 | 7 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 2 of the License, or 10 | # (at your option) any later version. 11 | 12 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with Foobar. If not, see . 19 | 20 | # exit after error 21 | set -e 22 | set -x 23 | 24 | echo "Test check_snmp_time2" 25 | py.test test/test_check_snmp_time2.py -v 26 | 27 | echo "Test check_meinberg_ntp" 28 | py.test test/test_check_meinberg_ntp.py -v 29 | 30 | echo "Test check_moxa_6000" 31 | py.test test/test_check_moxa_6000.py -v 32 | 33 | echo "Test check_snmp_ilo4" 34 | py.test test/test_check_snmp_ilo4.py -v 35 | 36 | echo "Test check_snmp_large_storage" 37 | py.test test/test_check_snmp_large_storage.py -v 38 | 39 | echo "Test check_snmp_service" 40 | py.test test/test_check_snmp_service.py -v 41 | 42 | echo "Test check_snmp_raritan" 43 | py.test test/test_check_snmp_raritan.py -v 44 | 45 | echo "Test check_snmp_port" 46 | py.test test/test_check_snmp_port.py -v 47 | 48 | echo "Test check_snmp_idrac" 49 | py.test test/test_check_snmp_idrac.py -v 50 | 51 | echo "Test check_snmp_teledyne" 52 | py.test test/test_check_snmp_teledyne.py -v 53 | 54 | echo "Test check_snmp_janitza" 55 | py.test test/test_check_snmp_janitza.py -v 56 | 57 | echo "Test check_snmp_ubiquiti" 58 | py.test test/test_check_snmp_ubiquiti.py -v 59 | 60 | echo "Test check_snmp_lband" 61 | py.test test/test_check_snmp_lband.py -v 62 | 63 | echo "Test check_snmp_apc_ups" 64 | py.test test/test_check_snmp_apc_ups.py -v 65 | 66 | echo "Test check_snmp_eaton_ups" 67 | py.test test/test_check_snmp_eaton_ups.py -v 68 | 69 | echo "Test check_snmp_procurve" 70 | py.test test/test_check_snmp_procurve.py -v 71 | 72 | echo "Test check_snmp_fortinet" 73 | py.test test/test_check_snmp_fortinet.py -v 74 | 75 | echo "Test check_snmp_trusted_filter" 76 | py.test test/test_check_snmp_trusted_filter.py -v 77 | 78 | echo "Test check_snmp_eps_plus" 79 | py.test test/test_check_snmp_eps_plus.py -v 80 | 81 | echo "Test check_newtecmodem" 82 | py.test test/test_check_newtecmodem.py -v 83 | 84 | echo "Test check_microwavemodem" 85 | py.test test/test_check_microwavemodem.py -v 86 | 87 | echo "Test check_cambium_ptp700" 88 | py.test test/test_check_smmp_cambium_ptp700.py -v -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (C) 2016-2019 rsmuc 4 | 5 | # This file is part of "Health Monitoring Plugins". 6 | 7 | # "Health Monitoring Plugins" is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 2 of the License, or 10 | # (at your option) any later version. 11 | 12 | # "Health Monitoring Plugins" is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with Foobar. If not, see . 19 | 20 | import sys 21 | import os 22 | from setuptools import setup, find_packages 23 | 24 | if sys.argv[-1] == 'test': 25 | test_requirements = ['pytest'] 26 | try: 27 | modules = map(__import__, test_requirements) 28 | except ImportError as e: 29 | err_msg = e.message.replace("No module named ", "") 30 | msg = "%s is not installed. Install your test requirements." % err_msg 31 | raise ImportError(msg) 32 | # the current testagent does not support starting and stopping the agent within one testrun, 33 | # so we need to call the script 34 | os.system('./run_unittest.sh') 35 | sys.exit() 36 | 37 | 38 | def read(fname): 39 | return open(os.path.join(os.path.dirname(__file__), fname)).read() 40 | 41 | 42 | setup(name='health_monitoring_plugins', 43 | version='0.2.1', 44 | description='Health monitoring plugins for icinga/nagios', 45 | url='https://codeberg.org/status_monitoring_tools/health_monitoring_plugins', 46 | author='rsmuc', 47 | author_email='rsmuc@sec-dev.de', 48 | license='GPLv2', 49 | classifiers=[ 50 | "Topic :: System :: Monitoring", 51 | "Development Status :: 5 - Production/Stable"], 52 | packages=find_packages(), 53 | package_data={'': ['*.md']}, 54 | long_description=read('README.md'), 55 | long_description_content_type='text/markdown', 56 | install_requires=['pynag'], 57 | scripts=[ 58 | 'health_monitoring_plugins/check_snmp_raritan/check_snmp_raritan.py', 59 | 'health_monitoring_plugins/check_meinberg_ntp/check_meinberg_ntp.py', 60 | 'health_monitoring_plugins/check_snmp_apc_ups/check_snmp_apc_ups.py', 61 | 'health_monitoring_plugins/check_snmp_eaton_ups/check_snmp_eaton_ups.py', 62 | 'health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py', 63 | 'health_monitoring_plugins/check_snmp_ilo4/check_snmp_ilo4.py', 64 | 'health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py', 65 | 'health_monitoring_plugins/check_snmp_port/check_snmp_port.py', 66 | 'health_monitoring_plugins/check_snmp_service/check_snmp_service.py', 67 | 'health_monitoring_plugins/check_snmp_time2/check_snmp_time2.py', 68 | 'health_monitoring_plugins/check_snmp_idrac/check_snmp_idrac.py', 69 | 'health_monitoring_plugins/check_snmp_janitza/check_snmp_janitza.py', 70 | 'health_monitoring_plugins/check_snmp_ubiquiti/check_snmp_ubiquiti.py', 71 | 'health_monitoring_plugins/check_snmp_teledyne/check_snmp_teledyne.py', 72 | 'health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py', 73 | 'health_monitoring_plugins/check_snmp_procurve/check_snmp_procurve.py', 74 | 'health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py', 75 | 'health_monitoring_plugins/check_local_cpu_temperature/check_local_cpu_temperature.py', 76 | 'health_monitoring_plugins/check_jenkins_api/check_jenkins_api.py', 77 | 'health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py', 78 | 'health_monitoring_plugins/check_snmp_inradios_csm/check_snmp_inradios_csm.py', 79 | 'health_monitoring_plugins/check_microwavemodem/check_microwavemodem.py', 80 | 'health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py', 81 | 'health_monitoring_plugins/check_snmp_eps_plus/check_snmp_eps_plus.py', 82 | 'health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py', 83 | 'health_monitoring_plugins/snmpSessionBaseClass.py', 84 | ], 85 | test_suite="test", 86 | include_package_data=True, 87 | zip_safe=False) 88 | -------------------------------------------------------------------------------- /test/context.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | tests_dir = os.path.dirname( os.path.abspath(__file__) ) 5 | package_path = os.path.join(tests_dir, '..') 6 | sys.path.insert(0, package_path) 7 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 8 | os.environ['PYTHONPATH'] = package_path 9 | testenv = os.environ 10 | -------------------------------------------------------------------------------- /test/snmpCSM_Server.mib: -------------------------------------------------------------------------------- 1 | INRADIOS DEFINITIONS ::= BEGIN 2 | IMPORTS 3 | Integer32, OBJECT-TYPE, NOTIFICATION-TYPE, Counter32, 4 | TimeTicks, Counter64, enterprises, MODULE-IDENTITY, 5 | Gauge32, IpAddress, DisplayString 6 | FROM SNMPv2-SMI; 7 | rsRoot MODULE-IDENTITY 8 | LAST-UPDATED "201803111306Z" 9 | ORGANIZATION "Rohde & Schwarz Inradios GmbH" 10 | CONTACT-INFO "www.inradios.com" 11 | DESCRIPTION "Inradios CSM Software Interface" 12 | REVISION "201803111306Z" 13 | DESCRIPTION "First release (1.00)" 14 | --NamesSpace MonitoringModule.Snmp 15 | --EnumName SnmpMibIdent 16 | --ClassName SnmpMonitoring 17 | ::= { enterprises 2566 } 18 | 19 | rsProduct OBJECT IDENTIFIER 20 | --WantTreeNum 127 21 | ::= { rsRoot 127 } 22 | 23 | rsProdSatelliteIntelligence OBJECT IDENTIFIER 24 | --WantTreeNum 6 25 | ::= { rsProduct 6 } 26 | 27 | rsProdSIInradios OBJECT IDENTIFIER 28 | --WantTreeNum 1 29 | ::= { rsProdSatelliteIntelligence 1 } 30 | 31 | software OBJECT IDENTIFIER 32 | --WantTreeNum 10 33 | ::= { rsProdSIInradios 10 } 34 | 35 | csmMonitoring OBJECT IDENTIFIER 36 | --WantTreeNum 1 37 | ::= { software 1 } 38 | 39 | csmMonitoringTable OBJECT-TYPE 40 | SYNTAX SEQUENCE OF CsmMonitoringTableTableEntry 41 | MAX-ACCESS not-accessible 42 | STATUS current 43 | DESCRIPTION "" 44 | --TableRowCount 1000 45 | ::= { csmMonitoring 1 } 46 | 47 | csmMonitoringTableTableEntry OBJECT-TYPE 48 | SYNTAX CsmMonitoringTableTableEntry 49 | MAX-ACCESS not-accessible 50 | STATUS current 51 | DESCRIPTION "" 52 | INDEX { csmMonitoringTableIndex } 53 | ::= { csmMonitoringTable 1 } 54 | 55 | CsmMonitoringTableTableEntry ::= SEQUENCE { 56 | mvComment DisplayString, 57 | mvValue DisplayString, 58 | mvValueDateTime DisplayString, 59 | mvParameter DisplayString, 60 | mvState INTEGER, 61 | mvUnit DisplayString, 62 | mvWarnThresholdUpper DisplayString, 63 | mvAlarmThresholdUpper DisplayString, 64 | mvWarnThresholdLower DisplayString, 65 | mvAlarmThresholdLower DisplayString, 66 | mvLabel DisplayString, 67 | csmMonitoringTableIndex Integer32 68 | } 69 | 70 | mvComment OBJECT-TYPE 71 | SYNTAX DisplayString 72 | MAX-ACCESS read-only 73 | STATUS current 74 | DESCRIPTION "shows which measurement is performed" 75 | ::= { csmMonitoringTableTableEntry 1 } 76 | 77 | mvValue OBJECT-TYPE 78 | SYNTAX DisplayString 79 | MAX-ACCESS read-only 80 | STATUS current 81 | DESCRIPTION "the Value of the last Measurement" 82 | ::= { csmMonitoringTableTableEntry 2 } 83 | 84 | mvValueDateTime OBJECT-TYPE 85 | SYNTAX DisplayString 86 | MAX-ACCESS read-only 87 | STATUS current 88 | DESCRIPTION "the Datetime of the last Measurement" 89 | ::= { csmMonitoringTableTableEntry 3 } 90 | 91 | mvParameter OBJECT-TYPE 92 | SYNTAX DisplayString 93 | MAX-ACCESS read-only 94 | STATUS current 95 | DESCRIPTION "describes the used parameters for the measurement" 96 | ::= { csmMonitoringTableTableEntry 4 } 97 | 98 | mvState OBJECT-TYPE 99 | SYNTAX INTEGER { notReady (0), notAvailable (1), OK (2), Warn (3), Alarm (4) } 100 | MAX-ACCESS read-only 101 | STATUS current 102 | DESCRIPTION "the current State of the MonitoringItem(notReady,notAvailable,OK,Warn,Alarm)" 103 | ::= { csmMonitoringTableTableEntry 5 } 104 | 105 | mvUnit OBJECT-TYPE 106 | SYNTAX DisplayString 107 | MAX-ACCESS read-only 108 | STATUS current 109 | DESCRIPTION "the Unit of the value" 110 | ::= { csmMonitoringTableTableEntry 6 } 111 | 112 | mvWarnThresholdUpper OBJECT-TYPE 113 | SYNTAX DisplayString 114 | MAX-ACCESS read-only 115 | STATUS current 116 | DESCRIPTION "the upper Warn Threshold for the value" 117 | ::= { csmMonitoringTableTableEntry 7 } 118 | 119 | mvAlarmThresholdUpper OBJECT-TYPE 120 | SYNTAX DisplayString 121 | MAX-ACCESS read-only 122 | STATUS current 123 | DESCRIPTION "the upper Alarm Threshold for the value" 124 | ::= { csmMonitoringTableTableEntry 8 } 125 | 126 | mvWarnThresholdLower OBJECT-TYPE 127 | SYNTAX DisplayString 128 | MAX-ACCESS read-only 129 | STATUS current 130 | DESCRIPTION "the lower Warn Threshold for the value" 131 | ::= { csmMonitoringTableTableEntry 9 } 132 | 133 | mvAlarmThresholdLower OBJECT-TYPE 134 | SYNTAX DisplayString 135 | MAX-ACCESS read-only 136 | STATUS current 137 | DESCRIPTION "the lower Alarm Threshold for the value" 138 | ::= { csmMonitoringTableTableEntry 10 } 139 | 140 | mvLabel OBJECT-TYPE 141 | SYNTAX DisplayString 142 | MAX-ACCESS read-only 143 | STATUS current 144 | DESCRIPTION "short Information Text" 145 | ::= { csmMonitoringTableTableEntry 11 } 146 | 147 | csmMonitoringTableIndex OBJECT-TYPE 148 | SYNTAX Integer32 149 | MAX-ACCESS not-accessible 150 | STATUS current 151 | DESCRIPTION "csmMonitoringTableIndex" 152 | ::= { csmMonitoringTableTableEntry 12 } 153 | 154 | END -------------------------------------------------------------------------------- /test/test_check_microwavemodem.py: -------------------------------------------------------------------------------- 1 | import context 2 | import subprocess 3 | import testagent 4 | 5 | testagent.configure(agent_address = "localhost:1234", 6 | rocommunity='public', rwcommunity='private') 7 | testagent.start_server() 8 | 9 | def notest_mib_not_reachable(): 10 | p=subprocess.Popen(("health_monitoring_plugins/check_microwavemodem/check_microwavemodem.py -H 127.0.0.1:1234 -m SK-IP"), 11 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 12 | p.wait() 13 | assert p.returncode == 3 14 | assert p.stdout.read() == "Unknown - SNMP response incomplete or invalid\n" 15 | p=subprocess.Popen(("health_monitoring_plugins/check_microwavemodem/check_microwavemodem.py -H 127.0.0.1:1234 -m AX-60"), 16 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 17 | p.wait() 18 | assert p.returncode == 3 19 | assert p.stdout.read() == "Unknown - SNMP response incomplete or invalid\n" 20 | 21 | def test_all_good(): 22 | walk = '''.1.3.6.1.4.1.29890.1.6.2.4.3.8.0 = INTEGER: 40 23 | .1.3.6.1.4.1.29890.1.6.2.4.3.9.0 = INTEGER: 40 24 | .1.3.6.1.4.1.29890.1.6.2.4.3.5.0 = INTEGER: 40 25 | .1.3.6.1.4.1.29890.1.6.2.4.3.6.0 = INTEGER: 40 26 | .1.3.6.1.4.1.29890.1.6.2.4.3.4.0 = INTEGER: 40 27 | .1.3.6.1.4.1.29890.1.6.2.4.3.7.0 = INTEGER: 40 28 | .1.3.6.1.4.1.29890.1.6.2.4.3.1.0 = INTEGER: 40 29 | .1.3.6.1.4.1.29890.1.6.2.4.4.2.1.0 = INTEGER: 100 30 | .1.3.6.1.4.1.29890.1.6.2.4.4.2.2.0 = INTEGER: 120 31 | .1.3.6.1.4.1.29890.1.6.2.4.4.2.3.0 = INTEGER: 250 32 | .1.3.6.1.4.1.29890.1.6.2.4.4.2.4.0 = INTEGER: 250 33 | .1.3.6.1.4.1.29890.1.6.2.4.4.2.5.0 = INTEGER: 330 34 | .1.3.6.1.4.1.29890.1.6.2.4.4.2.6.0 = INTEGER: 500 35 | .1.3.6.1.4.1.29890.1.6.2.4.4.2.7.0 = INTEGER: 900 36 | .1.3.6.1.4.1.29890.1.8.1.4.3.7.0 = INTEGER: 40000 37 | .1.3.6.1.4.1.29890.1.8.1.4.3.8.0 = INTEGER: 40000 38 | .1.3.6.1.4.1.29890.1.8.1.4.3.4.0 = INTEGER: 40000 39 | .1.3.6.1.4.1.29890.1.8.1.4.3.5.0 = INTEGER: 40000 40 | .1.3.6.1.4.1.29890.1.8.1.4.3.9.0 = INTEGER: 40000 41 | .1.3.6.1.4.1.29890.1.8.1.4.3.10.0 = INTEGER: 40000 42 | .1.3.6.1.4.1.29890.1.8.1.4.3.1.0 = INTEGER: 40000 43 | .1.3.6.1.4.1.29890.1.6.2.6.2.0 = STRING: "0000 0010" 44 | .1.3.6.1.4.1.29890.1.6.2.6.3.0 = STRING: "0000 0001" 45 | .1.3.6.1.4.1.29890.1.8.1.6.1.0 = INTEGER: 0''' 46 | testagent.register_snmpwalk_ouput(walk) 47 | p=subprocess.Popen(("health_monitoring_plugins/check_microwavemodem/check_microwavemodem.py -H 127.0.0.1:1234 -m SK-IP"), 48 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 49 | p.wait() 50 | assert p.returncode == 2 51 | assert p.stdout.read() == ( 52 | "WORK Microwave SK-IP Modem. System status: 1 error(s). Demodulator status: 1 warning(s). | " 53 | "'volt_dmd7'=9.0;;;; 'temp_demod_deg_c'=40.0;;;; 'volt_dmd5'=3.3;;;; 'volt_dmd4'=2.5;;;; " 54 | "'temp_demod_psu_deg_c'=40.0;;;; 'volt_dmd2'=1.2;;;; 'volt_dmd1'=1.0;;;; 'volt_dmd6'=5.0;;;; " 55 | "'temp_cpu2_deg_c'=40.0;;;; 'temp_ctl1_deg_c'=40.0;;;; 'temp_ctl2_deg_c'=40.0;;;; 'volt_dmd3'=2.5;;;; " 56 | "'temp_frontpanel_deg_c'=40.0;;;; 'temp_cpu1_deg_c'=40.0;;;;\n" 57 | "System: Mod. communication alarm\n" 58 | "Demodulator: FIFO full warning\n") 59 | p=subprocess.Popen(("health_monitoring_plugins/check_microwavemodem/check_microwavemodem.py -H 127.0.0.1:1234 -m AX-60"), 60 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 61 | p.wait() 62 | assert p.returncode == 0 63 | assert p.stdout.read() == ( 64 | "WORK Microwave AX-60 Modem. Global status: Ok. | 'temp_cpu_board_deg_c'=40.0;;;; " 65 | "'temp_cpu_deg_c'=40.0;;;; 'temp_demodulator_deg_c'=40.0;;;; 'temp_device_deg_c'=40.0;;;; " 66 | "'temp_bridge_chip_deg_c'=40.0;;;; 'temp_demodulator_board_deg_c'=40.0;;;; 'temp_bridge_board_deg_c'=40.0;;;;\n") 67 | 68 | def test_stop_server(): 69 | testagent.stop_server() 70 | -------------------------------------------------------------------------------- /test/test_check_moxa_6000.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import sys 4 | sys.path.insert(0, os.path.abspath('health_monitoring_plugins/check_moxa_6000')) 5 | 6 | from check_moxa_6000 import * 7 | 8 | import pytest 9 | import subprocess 10 | from testagent import * 11 | 12 | # configuration of the testagent 13 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 14 | configure(agent_address = "localhost:1234", 15 | rocommunity='public', rwcommunity='private') 16 | 17 | ##################################### 18 | # run the test for the old firmware # 19 | ##################################### 20 | 21 | def test_start(): 22 | # start the testagent 23 | # CTS 24 | # DSR 25 | # DTR 26 | # Error Count Frame 27 | walk = '''iso.3.6.1.4.1.8691.2.8.1.6.2.1.1.8.1 = INTEGER: 1 28 | iso.3.6.1.4.1.8691.2.8.1.6.2.1.1.5.1 = INTEGER: 1 29 | iso.3.6.1.4.1.8691.2.8.1.6.2.1.1.6.1 = INTEGER: 1 30 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.1.1 = INTEGER: 0 31 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.4.1 = INTEGER: 0 32 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.3.1 = INTEGER: 0 33 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.2.1 = INTEGER: 0''' 34 | register_snmpwalk_ouput(walk) 35 | start_server() 36 | 37 | def test_get_state(): 38 | """ 39 | get_state(value, warning_threshold, critical_threshold): 40 | """ 41 | assert get_state(10, 50, 100) == ok 42 | assert get_state(60, 50, 100) == warning 43 | assert get_state(200, 50, 100) == critical 44 | 45 | # integration test 46 | def test_system_test_moxa(capsys): 47 | # without options 48 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 49 | assert "Usage: check_moxa_6000.py [options]" in p.stdout.read() 50 | 51 | # without -H 1.2.3.4 (unknown host) 52 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 1.2.3.4", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 53 | assert "Usage: check_moxa_6000.py [options]\n\ncheck_moxa_6000.py: error: You must specifiy moxa rs232 port in order to run this plugin." in p.stdout.read() 54 | 55 | # without -H 1.2.3.4 (unknown host) -p 1 56 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 1.2.3.4 -p 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 57 | assert "Unknown - Can't connect to SNMP agent at application server or RS232 port does not exist." in p.stdout.read() 58 | 59 | # with --help 60 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py --help", shell=True, stdout=subprocess.PIPE) 61 | assert "Options:" in p.stdout.read() 62 | 63 | 64 | #def test_snmpv3(capsys): 65 | # # not reachable 66 | # p = subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -p 1 " + " -H 1.2.3.4 -V 3 " 67 | # "-U nothinguseful -L authNoPriv -a MD5 " 68 | # "-A nothinguseful -x DES -X nothinguseful --snmptimeout 3", 69 | # shell=True, stdout=subprocess.PIPE) 70 | # assert "Unknown - Can't connect to SNMP agent at application server or RS232 port does not exist" in p.stdout.read() 71 | 72 | 73 | def test_with_host_ok(): 74 | # everything ok 75 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 127.0.0.1:1234 -p 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 76 | assert "OK - CTS OK. DSR OK. DTR OK. ErrorCountFrame=0. ErrorCountBreak=0. ErrorCountOverrun=0. ErrorCountParity=0" in p.stdout.read() 77 | 78 | def test_with_host_ok_dsr_only(): 79 | # everything ok -t DSR 80 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 127.0.0.1:1234 -p 1 -t DSR", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 81 | assert "OK - DSR OK\nDSR (Data Set Ready) ready\n" in p.stdout.read() 82 | 83 | def test_all_nok(): 84 | # start the testagent 85 | # Old Firmware # NTP not ok and gps not ok 86 | unregister_all() 87 | walk = '''iso.3.6.1.4.1.8691.2.8.1.6.2.1.1.8.1 = INTEGER: 0 88 | iso.3.6.1.4.1.8691.2.8.1.6.2.1.1.5.1 = INTEGER: 0 89 | iso.3.6.1.4.1.8691.2.8.1.6.2.1.1.6.1 = INTEGER: 0 90 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.1.1 = INTEGER: 123 91 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.4.1 = INTEGER: 456 92 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.3.1 = INTEGER: 789 93 | iso.3.6.1.4.1.8691.2.8.1.6.3.1.1.2.1 = INTEGER: 101112''' 94 | 95 | register_snmpwalk_ouput(walk) 96 | 97 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 127.0.0.1:1234 -p 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 98 | assert "Critical - CTS NOK. DSR NOK. DTR NOK. ErrorCountFrame=123. ErrorCountBreak=456. ErrorCountOverrun=789. ErrorCountPari" in p.stdout.read() 99 | 100 | def test_with_host_nok_dsr_only(): 101 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 127.0.0.1:1234 -p 1 -t DSR", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 102 | assert "Critical - DSR NOK\nDSR (Data Set Ready) not ready\n" in p.stdout.read() 103 | 104 | def test_with_host_nok_dsr_only(): 105 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 127.0.0.1:1234 -p 1 -t DSR", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 106 | assert "Critical - DSR NOK\nDSR (Data Set Ready) not ready\n" in p.stdout.read() 107 | 108 | def test_with_host_nok_error_count_only(): 109 | p=subprocess.Popen("health_monitoring_plugins/check_moxa_6000/check_moxa_6000.py -H 127.0.0.1:1234 -p 1 -t ErrorCount", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 110 | assert "Warning - ErrorCountFrame=123. ErrorCountBreak=456. ErrorCountOverrun=789. ErrorCountParity=101112\nError Count Frame" in p.stdout.read() 111 | 112 | def test_stop(): 113 | # stop the testagent 114 | stop_server() 115 | -------------------------------------------------------------------------------- /test/test_check_newtecmodem.py: -------------------------------------------------------------------------------- 1 | import context 2 | import subprocess 3 | import testagent 4 | 5 | testagent.configure(agent_address = "localhost:1234", 6 | rocommunity='public', rwcommunity='private') 7 | testagent.start_server() 8 | 9 | def test_mib_not_reachable(): 10 | p=subprocess.Popen("health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py -H 127.0.0.1:1234 -m MDM6000", 11 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 12 | p.wait() 13 | assert p.returncode == 3 14 | assert p.stdout.read() == "Unknown - SNMP response incomplete or invalid\n" 15 | p=subprocess.Popen("health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py -H 127.0.0.1:1234 -m MDM6000", 16 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 17 | p.wait() 18 | assert p.returncode == 3 19 | assert p.stdout.read() == "Unknown - SNMP response incomplete or invalid\n" 20 | 21 | def test_all_good(): 22 | walk = '''.1.3.6.1.4.1.5835.5.2.5700.1.3.3.0 = INTEGER: 0 23 | .1.3.6.1.4.1.5835.5.2.5700.1.3.1.1.3.1 = INTEGER: 0 24 | .1.3.6.1.4.1.5835.5.2.100.1.10.11.0 = INTEGER: 0 25 | .1.3.6.1.4.1.5835.5.2.100.1.10.12.0 = INTEGER: 0 26 | .1.3.6.1.4.1.5835.5.2.100.1.10.6.0 = INTEGER: 0 27 | .1.3.6.1.4.1.5835.5.2.100.1.10.2.0 = INTEGER: 0 28 | .1.3.6.1.4.1.5835.5.2.100.1.10.1.0 = INTEGER: 0 29 | .1.3.6.1.4.1.5835.5.2.100.1.10.10.0 = INTEGER: 0 30 | .1.3.6.1.4.1.5835.5.2.100.1.10.5.0 = INTEGER: 0 31 | .1.3.6.1.4.1.5835.5.2.100.1.10.8.0 = INTEGER: 0 32 | .1.3.6.1.4.1.5835.5.2.100.1.10.7.0 = INTEGER: 0 33 | .1.3.6.1.4.1.5835.5.2.500.1.6.11.0 = INTEGER: 0 34 | .1.3.6.1.4.1.5835.5.2.500.1.6.12.0 = INTEGER: 0 35 | .1.3.6.1.4.1.5835.5.2.500.1.6.17.0 = INTEGER: 0 36 | .1.3.6.1.4.1.5835.5.2.3500.1.1.1.0 = INTEGER: 0 37 | .1.3.6.1.4.1.5835.5.2.4600.1.1.2.0 = INTEGER: 0 38 | .1.3.6.1.4.1.5835.5.2.4600.1.1.1.0 = INTEGER: 0 39 | .1.3.6.1.4.1.5835.5.2.100.1.9.2.0 = INTEGER: 251 40 | .1.3.6.1.4.1.5835.5.2.100.1.9.1.0 = INTEGER: 21''' 41 | testagent.register_snmpwalk_ouput(walk) 42 | p=subprocess.Popen("health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py -H 127.0.0.1:1234 -m MDM6000", 43 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 44 | p.wait() 45 | assert p.returncode == 0 46 | assert p.stdout.read() == "Newtec MDM6000. Status: OK. | 'power_v'=2.51;;;; 'temp_deg_c'=21.0;;;;\n" 47 | p=subprocess.Popen("health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py -H 127.0.0.1:1234 -m MDM9000", 48 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 49 | p.wait() 50 | assert p.returncode == 0 51 | assert p.stdout.read() == "Newtec MDM9000. Status: OK. | 'power_v'=2.51;;;; 'temp_deg_c'=21.0;;;;\n" 52 | 53 | def test_some_alarms(): 54 | testagent.unregister_all() 55 | walk = '''.1.3.6.1.4.1.5835.5.2.5700.1.3.3.0 = INTEGER: 1 56 | .1.3.6.1.4.1.5835.5.2.5700.1.3.1.1.3.1 = INTEGER: 0 57 | .1.3.6.1.4.1.5835.5.2.100.1.10.11.0 = INTEGER: 1 58 | .1.3.6.1.4.1.5835.5.2.100.1.10.12.0 = INTEGER: 0 59 | .1.3.6.1.4.1.5835.5.2.100.1.10.6.0 = INTEGER: 1 60 | .1.3.6.1.4.1.5835.5.2.100.1.10.2.0 = INTEGER: 0 61 | .1.3.6.1.4.1.5835.5.2.100.1.10.1.0 = INTEGER: 1 62 | .1.3.6.1.4.1.5835.5.2.100.1.10.10.0 = INTEGER: 0 63 | .1.3.6.1.4.1.5835.5.2.100.1.10.5.0 = INTEGER: 1 64 | .1.3.6.1.4.1.5835.5.2.100.1.10.8.0 = INTEGER: 0 65 | .1.3.6.1.4.1.5835.5.2.100.1.10.7.0 = INTEGER: 1 66 | .1.3.6.1.4.1.5835.5.2.500.1.6.11.0 = INTEGER: 0 67 | .1.3.6.1.4.1.5835.5.2.500.1.6.12.0 = INTEGER: 1 68 | .1.3.6.1.4.1.5835.5.2.500.1.6.17.0 = INTEGER: 0 69 | .1.3.6.1.4.1.5835.5.2.3500.1.1.1.0 = INTEGER: 1 70 | .1.3.6.1.4.1.5835.5.2.4600.1.1.2.0 = INTEGER: 0 71 | .1.3.6.1.4.1.5835.5.2.4600.1.1.1.0 = INTEGER: 1 72 | .1.3.6.1.4.1.5835.5.2.100.1.9.2.0 = INTEGER: 251 73 | .1.3.6.1.4.1.5835.5.2.100.1.9.1.0 = INTEGER: 21''' 74 | testagent.register_snmpwalk_ouput(walk) 75 | p=subprocess.Popen("health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py -H 127.0.0.1:1234 -m MDM6000", 76 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 77 | p.wait() 78 | assert p.returncode == 2 79 | assert p.stdout.read() == ( 80 | "Newtec MDM6000. Status: 7 alarms active. | 'power_v'=2.51;;;; 'temp_deg_c'=21.0;;;;\n" 81 | "Alarm: Antenna non-functional\n" 82 | "Alarm: Frontpanel communication failed\n" 83 | "Alarm: General device failure\n" 84 | "Alarm: License file non-existent or wrongly signed\n" 85 | "Alarm: Software upgrade failed\n" 86 | "Alarm: Failure is detected on data ethernet interface\n" 87 | "Alarm: Fan failure\n") 88 | p=subprocess.Popen("health_monitoring_plugins/check_newtecmodem/check_newtecmodem.py -H 127.0.0.1:1234 -m MDM9000", 89 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 90 | p.wait() 91 | assert p.returncode == 2 92 | assert p.stdout.read() == ( 93 | "Newtec MDM9000. Status: 9 alarms active. | 'power_v'=2.51;;;; 'temp_deg_c'=21.0;;;;\n" 94 | "Alarm: Antenna non-functional\n" 95 | "Alarm: Hardware malfunction\n" 96 | "Alarm: Frontpanel communication failed\n" 97 | "Alarm: General device failure\n" 98 | "Alarm: License file non-existent or wrongly signed\n" 99 | "Alarm: Software upgrade failed\n" 100 | "Alarm: Failure is detected on data ethernet interface\n" 101 | "Alarm: Fan failure\n" 102 | "Alarm: Converter not working due to hardware failures\n") 103 | 104 | def test_stop_server(): 105 | testagent.stop_server() 106 | -------------------------------------------------------------------------------- /test/test_check_snmp_cambium_ptp700.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import context 3 | import netsnmp 4 | import subprocess 5 | from health_monitoring_plugins.procurve import * 6 | from testagent import * 7 | 8 | # configuration of the testagent 9 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 10 | configure(agent_address="localhost:1234", 11 | rocommunity='public', rwcommunity='private') 12 | 13 | # create netsnmp Sessions for test_walk_data, test_check_udp, test_check_tcp 14 | session = netsnmp.Session(Version=2, DestHost='localhost', Community='public') 15 | failSession = netsnmp.Session(Version=2, DestHost='1.2.3.4', Community='public') 16 | test_session = netsnmp.Session(Version=2, DestHost='localhost:1234', Community='public') 17 | 18 | 19 | def test_start(): 20 | # everything ok 21 | walk = ''' 22 | iso.3.6.1.4.1.17713.9.12.16.0 = INTEGER: 0 23 | ''' 24 | register_snmpwalk_ouput(walk) 25 | start_server() 26 | 27 | 28 | # integration test 29 | def test_system_call(capsys): 30 | # without options 31 | p = subprocess.Popen( 32 | "python health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py", shell=True, 33 | stderr=subprocess.PIPE) 34 | assert "Hostname must be specified\n" in p.stderr.read() 35 | 36 | # with --help 37 | p = subprocess.Popen("python health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700" 38 | ".py --help", shell=True, stdout=subprocess.PIPE) 39 | assert "Options:" in p.stdout.read() 40 | 41 | 42 | def test_snmpv3(capsys): 43 | # not reachable 44 | 45 | p = subprocess.Popen( 46 | 'python health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py' + " -H 1.2.3.4 -V 3 " 47 | "-U nothinguseful -L authNoPriv -a MD5 " 48 | "-A nothinguseful -x DES -X nothinguseful --snmptimeout 3", 49 | shell=True, stdout=subprocess.PIPE) 50 | assert "Unknown - No response from device for oid .1.3.6.1.4.1.17713.9.12.16.0" in p.stdout.read() 51 | 52 | 53 | def test_ok(capsys): 54 | p = subprocess.Popen( 55 | "python health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py -H localhost:1234", 56 | shell=True, stdout=subprocess.PIPE) 57 | assert "OK - Radio is registering / connected" in p.stdout.read() 58 | 59 | 60 | def test_start_critical(): 61 | # sensors bad 62 | unregister_all() 63 | walk = ''' 64 | iso.3.6.1.4.1.17713.9.12.16.0 = INTEGER: 1 65 | ''' 66 | 67 | register_snmpwalk_ouput(walk) 68 | 69 | 70 | def test_critical(capsys): 71 | p = subprocess.Popen( 72 | "python health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py -H localhost:1234", 73 | shell=True, stdout=subprocess.PIPE) 74 | assert "Critical - Radio is searching / not connected" in p.stdout.read() 75 | 76 | 77 | 78 | 79 | def test_start_bad2(): 80 | unregister_all() 81 | walk = ''' 82 | iso.3.6.1.4.1.17713.9.12.16.0 = INTEGER: 2 83 | ''' 84 | register_snmpwalk_ouput(walk) 85 | 86 | def test_bad2(capsys): 87 | p = subprocess.Popen( 88 | "python health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py -H localhost:1234", 89 | shell=True, stdout=subprocess.PIPE) 90 | assert "Critical - Radio is acquiring / connecting" in p.stdout.read() 91 | 92 | 93 | 94 | 95 | def test_start_invalid(): 96 | unregister_all() 97 | walk = ''' 98 | iso.3.6.1.4.1.17713.9.12.16.0 = INTEGER: 4 99 | ''' 100 | register_snmpwalk_ouput(walk) 101 | 102 | 103 | def test_invalid(capsys): 104 | p = subprocess.Popen( 105 | "python health_monitoring_plugins/check_snmp_cambium_ptp700/check_snmp_cambium_ptp700.py -H localhost:1234", 106 | shell=True, stdout=subprocess.PIPE) 107 | assert "Critical - Radio is N/A" in p.stdout.read() 108 | 109 | 110 | def test_stop(): 111 | # stop the testagent 112 | stop_server() 113 | -------------------------------------------------------------------------------- /test/test_check_snmp_fortinet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import sys 4 | sys.path.insert(0, os.path.abspath('health_monitoring_plugins/check_snmp_fortinet')) 5 | 6 | from check_snmp_fortinet import * 7 | 8 | import pytest 9 | import subprocess 10 | from testagent import * 11 | 12 | # configuration of the testagent 13 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 14 | configure(agent_address = "localhost:1234", 15 | rocommunity='public', rwcommunity='private') 16 | 17 | # create netsnmp Sessions for test_walk_data, test_check_udp, test_check_tcp 18 | session = netsnmp.Session(Version=2, DestHost='localhost', Community='public') 19 | failSession = netsnmp.Session(Version=2, DestHost='1.2.3.4', Community='public') 20 | test_session = netsnmp.Session(Version=2, DestHost='localhost:1234', Community='public') 21 | 22 | def test_start(): 23 | # everything ok 24 | walk = ''' 25 | .1.3.6.1.4.1.15983.1.1.3.1.14.10.0 = INTEGER: 24 26 | .1.3.6.1.4.1.15983.1.1.3.1.14.13.0 = INTEGER: 23 27 | .1.3.6.1.4.1.15983.1.1.3.1.14.14.0 = INTEGER: 9 28 | .1.3.6.1.4.1.15983.1.1.3.1.14.16.0 = INTEGER: 22 29 | .1.3.6.1.4.1.15983.1.1.4.1.1.21.0 = INTEGER: 1 30 | .1.3.6.1.4.1.15983.1.1.4.1.1.22.0 = INTEGER: 3 31 | .1.3.6.1.4.1.15983.1.1.4.1.1.23.0 = INTEGER: 1 32 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.2.1 = STRING: "AP-1" 33 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.2.2 = STRING: "ApTest1" 34 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.21.1 = INTEGER: 1 35 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.21.2 = INTEGER: 1 36 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.26.1 = INTEGER: 1 37 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.26.2 = INTEGER: 1 38 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.27.1 = INTEGER: 3 39 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.27.2 = INTEGER: 3 40 | ''' 41 | register_snmpwalk_ouput(walk) 42 | start_server() 43 | 44 | #integration test 45 | def test_system_call(capsys): 46 | # without options 47 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py", shell=True, stdout=subprocess.PIPE) 48 | assert "Unknown - Hostname must be specified\n" in p.stdout.read() 49 | 50 | # with --help 51 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py --help", shell=True, stdout=subprocess.PIPE) 52 | assert "Options:" in p.stdout.read() 53 | 54 | def test_ok(capsys): 55 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234", shell=True, stdout=subprocess.PIPE) 56 | assert "OK - Controller Status" in p.stdout.read() 57 | 58 | 59 | def test_ok_ressources(capsys): 60 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234 --type=ressources", shell=True, stdout=subprocess.PIPE) 61 | result = p.stdout.read() 62 | assert "OK - Controller Status" in result 63 | assert "Memory: 22" in result 64 | 65 | def test_ok_controller(capsys): 66 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234 --type=controller", shell=True, stdout=subprocess.PIPE) 67 | result = p.stdout.read() 68 | assert "OK - Controller Status" in result 69 | assert "Controller Operational State: enabled" in result 70 | 71 | def test_ok_accesspoints(capsys): 72 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234 --type=accesspoints", shell=True, stdout=subprocess.PIPE) 73 | result = p.stdout.read() 74 | assert "OK - Access Points Status" in result 75 | assert "AP-1 - Operational: enabled - Availabilty: online - Alarm: no alarm" in result 76 | 77 | def test_start_critical(): 78 | # sensors bad 79 | unregister_all() 80 | walk = ''' .1.3.6.1.4.1.15983.1.1.3.1.14.10.0 = INTEGER: 99 81 | .1.3.6.1.4.1.15983.1.1.3.1.14.13.0 = INTEGER: 99 82 | .1.3.6.1.4.1.15983.1.1.3.1.14.14.0 = INTEGER: 99 83 | .1.3.6.1.4.1.15983.1.1.3.1.14.16.0 = INTEGER: 99 84 | .1.3.6.1.4.1.15983.1.1.4.1.1.21.0 = INTEGER: 2 85 | .1.3.6.1.4.1.15983.1.1.4.1.1.22.0 = INTEGER: 3 86 | .1.3.6.1.4.1.15983.1.1.4.1.1.23.0 = INTEGER: 1 87 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.2.1 = STRING: "AP-1" 88 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.2.2 = STRING: "ApTest1" 89 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.21.1 = INTEGER: 1 90 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.21.2 = INTEGER: 1 91 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.26.1 = INTEGER: 1 92 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.26.2 = INTEGER: 2 93 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.27.1 = INTEGER: 3 94 | .1.3.6.1.4.1.15983.1.1.4.2.1.1.27.2 = INTEGER: 6 95 | ''' 96 | 97 | register_snmpwalk_ouput(walk) 98 | 99 | 100 | def test_bad(capsys): 101 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234", shell=True, stdout=subprocess.PIPE) 102 | assert "Critical - Controller Status" in p.stdout.read() 103 | 104 | 105 | def test_bad_ressources(capsys): 106 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234 --type=ressources", shell=True, stdout=subprocess.PIPE) 107 | assert "Critical - Controller Status. Controller Ressources - CPU: 99" in p.stdout.read() 108 | 109 | def test_bad_controller(capsys): 110 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234 --type=controller", shell=True, stdout=subprocess.PIPE) 111 | assert "Critical - Controller Status" in p.stdout.read() 112 | 113 | def test_bad_accesspoints(capsys): 114 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_fortinet/check_snmp_fortinet.py -H localhost:1234 --type=accesspoints", shell=True, stdout=subprocess.PIPE) 115 | assert "Critical - Access Points Status. ApTest1 Operational State: disabled. ApTest1 Availability State: not installed" in p.stdout.read() 116 | 117 | 118 | 119 | def test_stop(): 120 | # stop the testagent 121 | stop_server() 122 | -------------------------------------------------------------------------------- /test/test_check_snmp_large_storage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import context 3 | import netsnmp 4 | import subprocess 5 | from health_monitoring_plugins.storage import * 6 | from testagent import * 7 | 8 | # configuration of the testagent 9 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 10 | configure(agent_address="localhost:1234", 11 | rocommunity='public', rwcommunity='private') 12 | 13 | # create netsnmp Sessions for test_get and test_walk_data 14 | session = netsnmp.Session(Version=2, DestHost='localhost', Community='public') 15 | failSession = netsnmp.Session(Version=2, DestHost='1.2.3.4', Community='public') 16 | 17 | 18 | def test_start(): 19 | # linux host 20 | walk = '''.1.3.6.1.2.1.25.2.3.1.1.10 = INTEGER: 10 21 | .1.3.6.1.2.1.25.2.3.1.1.31 = INTEGER: 31 22 | .1.3.6.1.2.1.25.2.3.1.3.10 = STRING: Swap space 23 | .1.3.6.1.2.1.25.2.3.1.3.31 = STRING: / 24 | .1.3.6.1.2.1.25.2.3.1.4.10 = INTEGER: 1024 25 | .1.3.6.1.2.1.25.2.3.1.4.31 = INTEGER: 4096 26 | .1.3.6.1.2.1.25.2.3.1.5.10 = INTEGER: 1324028 27 | .1.3.6.1.2.1.25.2.3.1.5.31 = INTEGER: 7381523 28 | .1.3.6.1.2.1.25.2.3.1.6.10 = INTEGER: 12504 29 | .1.3.6.1.2.1.25.2.3.1.6.31 = INTEGER: 628056''' 30 | register_snmpwalk_ouput(walk) 31 | start_server() 32 | 33 | 34 | def test_calculate_real_size(): 35 | """ 36 | test calculate_real_size 37 | """ 38 | assert calculate_real_size(5) == 5 39 | assert calculate_real_size(-5) == 2147483652 40 | 41 | 42 | def test_partition_found(): 43 | """ 44 | test partition_found(partition, description) 45 | """ 46 | assert partition_found("/etc", "/etc") == True 47 | assert partition_found("/etc", "/etc/var/bin/test") == False 48 | assert partition_found("C:\\", "C:\\ Data Test ID x123") == True 49 | assert partition_found("C:\\", "D:\\") == False 50 | 51 | 52 | # def test_convert_to_XX(capsys): 53 | # """ 54 | # test convert_to_XX(value, unit, targetunit) 55 | # """ 56 | # assert convert_to("1024", "4096", "MB") == 4 57 | # assert convert_to("1048576", "4096", "GB") == 4 58 | # assert convert_to("1073741824", "4096", "TB") == 4 59 | # with pytest.raises(SystemExit): 60 | # convert_to("1024", "4096", "XYZ") 61 | # out, err = capsys.readouterr() 62 | # assert "Unknown - Wrong targetunit: XYZ\n" == out 63 | 64 | 65 | def test_snmpv3(capsys): 66 | # not reachable 67 | 68 | p = subprocess.Popen( 69 | 'health_monitoring_plugins/check_snmp_idrac/check_snmp_idrac.py' + " -H 1.2.3.4 -V 3 " 70 | "-U nothinguseful -L authNoPriv -a MD5 " 71 | "-A nothinguseful -x DES -X nothinguseful --snmptimeout 3", 72 | shell=True, stdout=subprocess.PIPE) 73 | assert "Unknown - No response from device for oid .1.3.6.1.2.1.1.5.0" in p.stdout.read() 74 | 75 | 76 | def test_without_options(capsys): 77 | # without options 78 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_service/check_snmp_service.py", 79 | shell=True, stderr=subprocess.PIPE) 80 | assert "Hostname must be specified\n" in p.stderr.read() 81 | 82 | 83 | def test_help(): 84 | # with --help 85 | p = subprocess.Popen( 86 | "health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py --help", 87 | shell=True, stdout=subprocess.PIPE) 88 | assert "Options:" in p.stdout.read() 89 | 90 | 91 | def test_scan(): 92 | # scan 93 | p = subprocess.Popen( 94 | "health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py -H 127.0.0.1:1234", 95 | shell=True, stdout=subprocess.PIPE) 96 | assert "All available disks at: 127.0.0.1:1234\nDisk: \t'Swap space'" in p.stdout.read() 97 | 98 | 99 | def test_root_partition(): 100 | # root partition 101 | p = subprocess.Popen( 102 | "health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py -H 127.0.0.1:1234 -p /", 103 | shell=True, stdout=subprocess.PIPE) 104 | assert "OK - 8.51% used (2.4GB of 28.16GB) at '/' | 'percent used'=8.51%;;;0;100" in p.stdout.read() 105 | 106 | 107 | def test_root_partition_warning(): 108 | # root partition in warning 109 | p = subprocess.Popen( 110 | "health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py -H 127.0.0.1:1234 -p / --threshold metric='percent used',warning=5..inf,critical=95..inf", 111 | shell=True, stdout=subprocess.PIPE) 112 | assert "Warning - 8.51% used (2.4GB of 28.16GB) at '/'. Warning on percent used | 'percent used'=8.51%;~:5;~:95;0;100\n" in p.stdout.read() 113 | 114 | 115 | def test_root_partition_in_tb(): 116 | # root partition in TB 117 | p = subprocess.Popen( 118 | "health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py -H 127.0.0.1:1234 -p / -u TB", 119 | shell=True, stdout=subprocess.PIPE) 120 | assert "OK - 8.51% used (0.0TB of 0.03TB) at '/' | 'percent used'=8.51%;;;0;100\n" in p.stdout.read() 121 | 122 | 123 | def test_root_partition_in_mb(): 124 | # root partition in TB 125 | p = subprocess.Popen( 126 | "health_monitoring_plugins/check_snmp_large_storage/check_snmp_large_storage.py -H 127.0.0.1:1234 -p / -u MB", 127 | shell=True, stdout=subprocess.PIPE) 128 | assert "OK - 8.51% used (2453.34MB of 28834.07MB) at '/' | 'percent used'=8.51%;;;0;100\n" in p.stdout.read() 129 | 130 | 131 | def test_stop(): 132 | # stop the testagent 133 | stop_server() 134 | -------------------------------------------------------------------------------- /test/test_check_snmp_lband.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # test_check_snmp_lband.py - test Monitor a L-band redundancy controller via SNMP. 4 | 5 | # Copyright (C) 2017 rsmuc rsmuc@sec-dev.de 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public License 9 | # as published by the Free Software Foundation; either version 2 10 | # of the License, or (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along test_check_snmp_lband.py. If not, see . 19 | 20 | import os 21 | import sys 22 | sys.path.insert(0, os.path.abspath('health_monitoring_plugins/check_snmp_lband')) 23 | from check_snmp_lband import * 24 | 25 | import pytest 26 | import subprocess 27 | from testagent import * 28 | 29 | # configuration of the testagent 30 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 31 | configure(agent_address = "localhost:1234", rocommunity='public', rwcommunity='private') 32 | 33 | # create netsnmp Session for test_get, test_walk ant test_attempt_walk 34 | session = netsnmp.Session(Version=2, DestHost='localhost', Community='public') 35 | failSession = netsnmp.Session(Version=2, DestHost='1.2.3.4', Community='public') 36 | 37 | def test_start(): 38 | # start the testagent 39 | walk = '''.1.3.6.1.4.1.31210.52.1.9.0 = INTEGER: 0 40 | .1.3.6.1.4.1.31210.52.1.13.0 = INTEGER: 0''' 41 | register_snmpwalk_ouput(walk) 42 | start_server() 43 | 44 | def test_Lband_basics(): 45 | #without options 46 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 47 | myout = p.stdout.read() 48 | print "--------------------" 49 | print "got" 50 | print myout 51 | print "expected" 52 | print "Unknown - Hostname must be specified" 53 | print "--------------------" 54 | assert "Unknown - Hostname must be specified" in myout 55 | # with unknown host (-H 1.2.3.4) 56 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py -H 1.2.3.4 -U 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 57 | myout = p.stdout.read() 58 | assert "Unknown - snmpget failed - no data for host 1.2.3.4 OID: .1.3.6.1.4.1.31210.52.1.9.0\n" in myout 59 | 60 | # test if result without -U switch is correct 61 | def test_ok_outputs(): 62 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py -H 127.0.0.1:1234", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 63 | myout = p.stdout.read() 64 | print "--------------------" 65 | print "got" 66 | print myout 67 | print "expected" 68 | print "OK - Unit status is: Online" 69 | print "--------------------" 70 | assert "OK - Unit status is: Online" in myout 71 | 72 | # test if -U switch is working 73 | def test_ok(): 74 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py -H 127.0.0.1:1234 -U 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 75 | assert "OK - Unit status is: Online" in p.stdout.read() 76 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py -H 127.0.0.1:1234 -U 2", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 77 | assert "OK - Unit status is: Online" in p.stdout.read() 78 | 79 | def test_start_critical(): 80 | unregister_all() 81 | walk = '''.1.3.6.1.4.1.31210.52.1.9.0 = INTEGER: 2 82 | .1.3.6.1.4.1.31210.52.1.13.0 = INTEGER: 2''' 83 | 84 | register_snmpwalk_ouput(walk) 85 | 86 | def test_critical_output(): 87 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py -H 127.0.0.1:1234", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 88 | myout = p.stdout.read() 89 | 90 | print "--------------------" 91 | print "got" 92 | print myout 93 | print "expected" 94 | print "Critical - Unit status is: Alarmed" 95 | print "--------------------" 96 | assert "Critical - Unit status is: Alarmed" in myout 97 | 98 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py -H 127.0.0.1:1234 -U 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 99 | assert "Critical - Unit status is: Alarmed" in p.stdout.read() 100 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_lband/check_snmp_lband.py -H 127.0.0.1:1234 -U 2", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 101 | assert "Critical - Unit status is: Alarmed" in p.stdout.read() 102 | 103 | 104 | def test_stop_final(): 105 | # stop the testagent 106 | stop_server() 107 | -------------------------------------------------------------------------------- /test/test_check_snmp_s650.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # test_check_snmp_s650.py - test Monitor a L-band redundancy controller via SNMP. 4 | 5 | # Copyright (C) 2017 rsmuc rsmuc@sec-dev.de 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public License 9 | # as published by the Free Software Foundation; either version 2 10 | # of the License, or (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along test_check_snmp_s650.py. If not, see . 19 | 20 | import os 21 | import sys 22 | sys.path.insert(0, os.path.abspath('health_monitoring_plugins/check_snmp_s650')) 23 | from check_snmp_s650 import * 24 | 25 | import pytest 26 | import subprocess 27 | from testagent import * 28 | 29 | # configuration of the testagent 30 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 31 | configure(agent_address = "localhost:1234", rocommunity='public', rwcommunity='private') 32 | 33 | # create netsnmp Session for test_get, test_walk ant test_attempt_walk 34 | session = netsnmp.Session(Version=2, DestHost='localhost', Community='public') 35 | failSession = netsnmp.Session(Version=2, DestHost='1.2.3.4', Community='public') 36 | 37 | base_oid= 'iso.3.6.1.4.1.31210.52.1.' 38 | walk_var = "" 39 | 40 | def test_start(): 41 | # start the testagent 42 | walk = '''iso.1.3.6.1.4.1.31210.52.1.9.0 = INTEGER: 0 43 | iso.1.3.6.1.4.1.31210.52.1.13.0 = INTEGER: 0''' 44 | register_snmpwalk_ouput(walk) 45 | start_server() 46 | 47 | def test_Lband_basics(): 48 | #without options 49 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 50 | myout = p.stdout.read() 51 | print "--------------------" 52 | print "got" 53 | print myout 54 | print "expected" 55 | print "Unknown - Hostname must be specified" 56 | print "--------------------" 57 | assert "Unknown - Hostname must be specified" in myout 58 | # with unknown host (-H 1.2.3.4) 59 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py -H 1.2.3.4 -U 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 60 | assert "Unknown - snmpget failed - no data for host 1.2.3.4 OID: iso.1.3.6.1.4.1.31210.52.1.9.0\n" in p.stdout.read() 61 | 62 | # test if result without -U switch is correct 63 | def test_ok_outputs(): 64 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py -H 127.0.0.1:1234", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 65 | myout = p.stdout.read() 66 | print "--------------------" 67 | print "got" 68 | print myout 69 | print "expected" 70 | print "OK - Unit status is: Online" 71 | print "--------------------" 72 | assert "OK - Unit status is: Online" in myout 73 | 74 | # test if -U switch is working 75 | def test_ok(): 76 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py -H 127.0.0.1:1234 -U 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 77 | assert "OK - Unit status is: Online" in p.stdout.read() 78 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py -H 127.0.0.1:1234 -U 2", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 79 | assert "OK - Unit status is: Online" in p.stdout.read() 80 | 81 | def test_start_critical(): 82 | unregister_all() 83 | walk = '''iso.1.3.6.1.4.1.31210.52.1.9.0 = INTEGER: 2 84 | iso.1.3.6.1.4.1.31210.52.1.13.0 = INTEGER: 2''' 85 | 86 | register_snmpwalk_ouput(walk) 87 | 88 | def test_critical_output(): 89 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py -H 127.0.0.1:1234", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 90 | myout = p.stdout.read() 91 | 92 | print "--------------------" 93 | print "got" 94 | print myout 95 | print "expected" 96 | print "Critical - Unit status is: Alarmed" 97 | print "--------------------" 98 | assert "Critical - Unit status is: Alarmed" in myout 99 | 100 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py -H 127.0.0.1:1234 -U 1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 101 | assert "Critical - Unit status is: Alarmed" in p.stdout.read() 102 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_s650/check_snmp_s650.py -H 127.0.0.1:1234 -U 2", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 103 | assert "Critical - Unit status is: Alarmed" in p.stdout.read() 104 | 105 | 106 | def test_stop_final(): 107 | # stop the testagent 108 | stop_server() 109 | -------------------------------------------------------------------------------- /test/test_check_snmp_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import context 3 | import netsnmp 4 | import subprocess 5 | from health_monitoring_plugins.windowsservice import * 6 | from testagent import * 7 | 8 | # configuration of the testagent 9 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 10 | configure(agent_address="localhost:1234", 11 | rocommunity='public', rwcommunity='private') 12 | 13 | # create netsnmp Session for test_attempt_get and test_walk 14 | session = netsnmp.Session(Version=2, DestHost='localhost', Community='public') 15 | failSession = netsnmp.Session(Version=2, DestHost='1.2.3.4', Community='public') 16 | 17 | 18 | def test_start(): 19 | # some open Windows services 20 | walk = '''.1.3.6.1.4.1.77.1.2.3.1.1.5.80.111.119.101.114 = STRING: "Power" 21 | .1.3.6.1.4.1.77.1.2.3.1.1.6.83.101.114.118.101.114 = STRING: "Server" 22 | .1.3.6.1.4.1.77.1.2.3.1.1.6.84.104.101.109.101.115 = STRING: "Themes" 23 | .1.3.6.1.4.1.77.1.2.3.1.1.9.73.80.32.72.101.108.112.101.114 = STRING: "IP Helper"''' 24 | register_snmpwalk_ouput(walk) 25 | start_server() 26 | 27 | 28 | def test_oid_conversion(): 29 | """ 30 | test convert_in_oid 31 | """ 32 | assert convert_in_oid( 33 | "IP Helper") == ".1.3.6.1.4.1.77.1.2.3.1.1.9.73.80.32.72.101.108.112.101.114" 34 | 35 | 36 | def test_without_options(capsys): 37 | # without options 38 | p = subprocess.Popen("health_monitoring_plugins/check_snmp_service/check_snmp_service.py", 39 | shell=True, stderr=subprocess.PIPE) 40 | assert "Hostname must be specified\n" in p.stderr.read() 41 | 42 | 43 | def test_help(): 44 | # with --help 45 | p = subprocess.Popen( 46 | "health_monitoring_plugins/check_snmp_service/check_snmp_service.py --help", shell=True, 47 | stdout=subprocess.PIPE) 48 | assert "Options:" in p.stdout.read() 49 | 50 | 51 | def test_scan(): 52 | # with service scan 53 | p = subprocess.Popen( 54 | "health_monitoring_plugins/check_snmp_service/check_snmp_service.py -H 127.0.0.1:1234 -S", 55 | shell=True, stdout=subprocess.PIPE) 56 | assert "Running services at host: 127.0.0.1:1234\nService: \t'Power'\nService: \t'Server'\nService: \t'Themes" in p.stdout.read() 57 | 58 | 59 | def test_service_available(): 60 | # with service "IP Helper" available 61 | p = subprocess.Popen( 62 | "health_monitoring_plugins/check_snmp_service/check_snmp_service.py -H 127.0.0.1:1234 -s 'IP Helper'", 63 | shell=True, stdout=subprocess.PIPE) 64 | assert "OK - Status of Service 'IP Helper' is: RUNNING\n" in p.stdout.read() 65 | 66 | # with service "Test" not available 67 | p = subprocess.Popen( 68 | "health_monitoring_plugins/check_snmp_service/check_snmp_service.py -H 127.0.0.1:1234 -s 'Test'", 69 | shell=True, stdout=subprocess.PIPE) 70 | assert "Critical - Status of Service 'Test' is: NOT RUNNING\n" in p.stdout.read() 71 | 72 | 73 | def test_stop(): 74 | # stop the testagent 75 | stop_server() 76 | -------------------------------------------------------------------------------- /test/test_check_snmp_teledyne.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import sys 4 | sys.path.insert(0, os.path.abspath('health_monitoring_plugins/check_snmp_teledyne')) 5 | 6 | #from check_snmp_teledyne import * 7 | 8 | import pytest 9 | import subprocess 10 | from testagent import * 11 | 12 | # configuration of the testagent 13 | os.environ['MIBDIRS'] = os.path.dirname(os.path.abspath(__file__)) 14 | configure(agent_address = "localhost:1234", 15 | rocommunity='public', rwcommunity='private') 16 | 17 | 18 | def test_start(): 19 | # start the testagent 20 | # Gauge32 are not working - So I replaced them by INTEGER 21 | # # Everything ok 22 | 23 | #Unit1FaultState 24 | #Unit2FaultState 25 | #Unit3FaultState 26 | #SummaryFaultState 27 | #PS12 FaultState 28 | #RFSwitch12State 29 | 30 | walk = ''' 31 | iso.3.6.1.4.1.20712.2.1.3.1.2.1 = INTEGER: 0 32 | iso.3.6.1.4.1.20712.2.1.3.1.2.2 = INTEGER: 0 33 | iso.3.6.1.4.1.20712.2.1.3.1.2.3 = INTEGER: 0 34 | iso.3.6.1.4.1.20712.2.1.3.1.2.4 = INTEGER: 0 35 | iso.3.6.1.4.1.20712.2.1.3.1.2.5 = INTEGER: 0 36 | iso.3.6.1.4.1.20712.2.1.3.1.2.6 = INTEGER: 0 37 | iso.3.6.1.4.1.20712.2.1.3.1.2.11 = INTEGER: 0 38 | iso.3.6.1.4.1.20712.2.1.3.1.2.12 = INTEGER: 0 39 | ''' 40 | register_snmpwalk_ouput(walk) 41 | start_server() 42 | 43 | # integration test 44 | def test_system_test_teledyne(capsys): 45 | # without options 46 | p=subprocess.Popen("health_monitoring_plugins/check_snmp_teledyne/check_snmp_teledyne.py", shell=True, stdout=subprocess.PIPE) 47 | assert "Unknown - Hostname must be specified" in p.stdout.read() 48 | 49 | # without -H 1.2.3.4 (unknown host) 50 | p=subprocess.Popen("health_monitoring_plugins/check_snmp_teledyne/check_snmp_teledyne.py -H 1.2.3.4", shell=True, stdout=subprocess.PIPE) 51 | assert "Unknown - snmpget failed - no data" in p.stdout.read() 52 | 53 | # with --help 54 | p=subprocess.Popen("health_monitoring_plugins/check_snmp_teledyne/check_snmp_teledyne.py --help", shell=True, stdout=subprocess.PIPE) 55 | assert "Options:" in p.stdout.read() 56 | 57 | def test_with_host_ok(): 58 | # everything ok 59 | p=subprocess.Popen("health_monitoring_plugins/check_snmp_teledyne/check_snmp_teledyne.py -H localhost:1234", shell=True, stdout=subprocess.PIPE) 60 | assert "OK - Fault Summary: No Fault. Power Supply 1: No Fault. Power Supply 2: No Fault. RF Switch 1: No Fault. RF Switch 2: No Fault. Unit 1: No Fault. Unit 2: No Fault. Unit 3: No Fault" in p.stdout.read() 61 | 62 | 63 | def test_with_all_nok(): 64 | # start the testagent 65 | # Everything is CRITICAL 66 | unregister_all() 67 | walk = ''' 68 | iso.3.6.1.4.1.20712.2.1.3.1.2.1 = INTEGER: 1 69 | iso.3.6.1.4.1.20712.2.1.3.1.2.2 = INTEGER: 1 70 | iso.3.6.1.4.1.20712.2.1.3.1.2.3 = INTEGER: 1 71 | iso.3.6.1.4.1.20712.2.1.3.1.2.4 = INTEGER: 1 72 | iso.3.6.1.4.1.20712.2.1.3.1.2.5 = INTEGER: 1 73 | iso.3.6.1.4.1.20712.2.1.3.1.2.6 = INTEGER: 1 74 | iso.3.6.1.4.1.20712.2.1.3.1.2.11 = INTEGER: 1 75 | iso.3.6.1.4.1.20712.2.1.3.1.2.12 = INTEGER: 1 76 | ''' 77 | register_snmpwalk_ouput(walk) 78 | 79 | p=subprocess.Popen("health_monitoring_plugins/check_snmp_teledyne/check_snmp_teledyne.py -H localhost:1234", shell=True, stdout=subprocess.PIPE) 80 | assert "Critical - Fault Summary: Fault. Power Supply 1: Fault. Power Supply 2: Fault. RF Switch 1: Fault. RF Switch 2: Fault. Unit 1: Fault. Unit 2: Fault. Unit 3: Fault" in p.stdout.read() 81 | 82 | 83 | def test_stop(): 84 | # stop the testagent 85 | stop_server() 86 | -------------------------------------------------------------------------------- /test/test_check_snmp_trusted_filter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import context 3 | import subprocess 4 | import testagent 5 | 6 | testagent.configure(agent_address = "localhost:1234", 7 | rocommunity='public', rwcommunity='private') 8 | 9 | def test_start_snmp_simulation(): 10 | testagent.start_server() 11 | 12 | #integration test 13 | def test_options(): 14 | # without options 15 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py", 16 | shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=context.testenv) 17 | assert "error: Hostname must be specified" in p.stderr.read() 18 | # with --help 19 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py --help", 20 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 21 | assert "Options:" in p.stdout.read() 22 | 23 | def test_trustedfilter_ok(): 24 | walk = ''' 25 | .1.3.6.1.4.1.2566.107.41.1.0 = INTEGER: 1 26 | .1.3.6.1.4.1.2566.107.31.2.1.0 = INTEGER: 80 27 | .1.3.6.1.4.1.2566.107.31.2.2.0 = INTEGER: 1 28 | .1.3.6.1.4.1.2566.107.31.2.3.0 = INTEGER: 1 29 | .1.3.6.1.4.1.2566.107.31.2.4.0 = INTEGER: 1 30 | .1.3.6.1.4.1.2566.107.31.2.5.0 = INTEGER: 1 31 | .1.3.6.1.4.1.2566.107.31.2.7.0 = INTEGER: 1 32 | .1.3.6.1.4.1.2566.107.31.2.8.0 = INTEGER: 1 33 | ''' 34 | testagent.register_snmpwalk_ouput(walk) 35 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py -H localhost:1234", 36 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 37 | assert p.stdout.read() == ( 38 | "OK - Filter Status | 'logfill'=80%%;;;;\n" 39 | "Power Supply 1: ok\n" 40 | "Power Supply 2: ok\n" 41 | "Fan 1: ok\nFan 2: ok\n" 42 | "Battery: ok\n" 43 | "Temperature: ok\n" 44 | "Fill Level internal log: 80%\n" 45 | "Activity State: standby\n") 46 | 47 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py -H localhost:1234 -s localhost:1234", 48 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 49 | assert p.stdout.read() == ( 50 | "Critical - Filter Status. Filter 1 and Filter 2 standby! | 'logfill'=80%%;;;;\n" 51 | "Power Supply 1: ok\n" 52 | "Power Supply 2: ok\n" 53 | "Fan 1: ok\n" 54 | "Fan 2: ok\n" 55 | "Battery: ok\nTemperature: ok\n" 56 | "Fill Level internal log: 80%\n" 57 | "Activity State: standby\n" 58 | "Activity State 2: standby\n") 59 | testagent.unregister_all() 60 | 61 | def test_trustedfilter_ps_absent(): 62 | walk = ''' 63 | .1.3.6.1.4.1.2566.107.41.1.0 = INTEGER: 1 64 | .1.3.6.1.4.1.2566.107.31.2.1.0 = INTEGER: 80 65 | .1.3.6.1.4.1.2566.107.31.2.2.0 = INTEGER: 3 66 | .1.3.6.1.4.1.2566.107.31.2.3.0 = INTEGER: 3 67 | .1.3.6.1.4.1.2566.107.31.2.4.0 = INTEGER: 1 68 | .1.3.6.1.4.1.2566.107.31.2.5.0 = INTEGER: 1 69 | .1.3.6.1.4.1.2566.107.31.2.7.0 = INTEGER: 1 70 | .1.3.6.1.4.1.2566.107.31.2.8.0 = INTEGER: 1 71 | ''' 72 | testagent.register_snmpwalk_ouput(walk) 73 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py -H localhost:1234", 74 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 75 | assert p.stdout.read() == ( 76 | "Critical - Filter Status. Power Supply 1: absent. Power Supply 2: absent | 'logfill'=80%%;;;;\n" 77 | "Power Supply 1: absent\n" 78 | "Power Supply 2: absent\n" 79 | "Fan 1: ok\n" 80 | "Fan 2: ok\n" 81 | "Battery: ok\n" 82 | "Temperature: ok\n" 83 | "Fill Level internal log: 80%\n" 84 | "Activity State: standby\n") 85 | testagent.unregister_all() 86 | 87 | def test_trustedfilter_ps_acoff(): 88 | walk = ''' 89 | .1.3.6.1.4.1.2566.107.41.1.0 = INTEGER: 1 90 | .1.3.6.1.4.1.2566.107.31.2.1.0 = INTEGER: 80 91 | .1.3.6.1.4.1.2566.107.31.2.2.0 = INTEGER: 4 92 | .1.3.6.1.4.1.2566.107.31.2.3.0 = INTEGER: 4 93 | .1.3.6.1.4.1.2566.107.31.2.4.0 = INTEGER: 1 94 | .1.3.6.1.4.1.2566.107.31.2.5.0 = INTEGER: 1 95 | .1.3.6.1.4.1.2566.107.31.2.7.0 = INTEGER: 1 96 | .1.3.6.1.4.1.2566.107.31.2.8.0 = INTEGER: 1 97 | ''' 98 | testagent.register_snmpwalk_ouput(walk) 99 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py -H localhost:1234", 100 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 101 | assert p.stdout.read() == ( 102 | "Critical - Filter Status. Power Supply 1: AC off. Power Supply 2: AC off | 'logfill'=80%%;;;;\n" 103 | "Power Supply 1: AC off\n" 104 | "Power Supply 2: AC off\n" 105 | "Fan 1: ok\n" 106 | "Fan 2: ok\n" 107 | "Battery: ok\n" 108 | "Temperature: ok\n" 109 | "Fill Level internal log: 80%\n" 110 | "Activity State: standby\n") 111 | testagent.unregister_all() 112 | 113 | def test_stop_snmp_simulation(): 114 | testagent.stop_server() 115 | 116 | def test_no_agent(): 117 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py -H localhost:1234", 118 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 119 | assert p.stdout.read() == "Unknown - SNMP response incomplete or invalid\n" 120 | 121 | def test_no_host(): 122 | p=subprocess.Popen("python health_monitoring_plugins/check_snmp_trusted_filter/check_snmp_trusted_filter.py -H 1.2.3.4:1234", 123 | shell=True, stdout=subprocess.PIPE, env=context.testenv) 124 | assert p.stdout.read() == "Unknown - SNMP response incomplete or invalid\n" -------------------------------------------------------------------------------- /test/test_snmpSessionBaseClass.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import sys 4 | sys.path.insert(0, os.path.abspath('health_monitoring_plugins')) 5 | 6 | import netsnmp 7 | import pytest 8 | import subprocess 9 | import pynag 10 | 11 | import snmpSessionBaseClass 12 | 13 | 14 | # States definitions 15 | normal_state = { 16 | 1 : 'other', 17 | 2 : 'ok', 18 | 3 : 'degraded', 19 | 4 : 'failed' 20 | } 21 | 22 | # create an instance of PluginHelper() 23 | helper = pynag.Plugins.PluginHelper() 24 | 25 | # create netsnmp Session for test_get, test_attempt_get, test_walk and test_attempt_walk 26 | session = netsnmp.Session(Version=2, DestHost='localhost', Community='public') 27 | failSession = netsnmp.Session(Version=2, DestHost='1.2.3.4', Community='public') 28 | 29 | def get_system_uptime(): 30 | """ 31 | just a helper to get the system uptime in seconds 32 | """ 33 | with open('/proc/uptime', 'r') as f: 34 | uptime_seconds = str(f.readline().split()[0]) 35 | uptime_seconds = uptime_seconds.replace('.', '') 36 | return str(uptime_seconds) 37 | 38 | def test_get(capsys): 39 | """ 40 | test of the get_data function 41 | """ 42 | # run a get on a not existing host 43 | with pytest.raises(SystemExit): 44 | snmpSessionBaseClass.get_data(failSession, '.1', helper) 45 | out, err = capsys.readouterr() 46 | assert 'Unknown - snmpget failed - no data for host' in out 47 | # check if we receive the system uptime via snmp and compare it with the local uptime from /proc/uptime (except the last digit) 48 | assert snmpSessionBaseClass.get_data( 49 | session, '.1.3.6.1.2.1.25.1.1.0', helper)[:-2]\ 50 | == get_system_uptime()[:-2] 51 | 52 | def test_attempt_data(): 53 | """ 54 | test of the attempt_get_data function 55 | """ 56 | # try to get data from a not existing host 57 | assert snmpSessionBaseClass.attempt_get_data(failSession, '.1') == None 58 | # check if we receive the system uptime via snmp and compare it with the local uptime from /proc/uptime (except the last digit) 59 | assert snmpSessionBaseClass.attempt_get_data( 60 | session, '.1.3.6.1.2.1.25.1.1.0')[:-2] == get_system_uptime()[:-2] 61 | 62 | def test_walk_data(capsys): 63 | """ 64 | test of the walk_data function 65 | """ 66 | #run a walk on a not existing host 67 | with pytest.raises(SystemExit): 68 | assert snmpSessionBaseClass.walk_data(failSession, '.1', helper) 69 | out, err = capsys.readouterr() 70 | assert 'Unknown - snmpwalk failed - no data for host' in out 71 | # check if we receive the system uptime via snmp and compare it with the local uptime from /proc/uptime (except the last digit) 72 | assert snmpSessionBaseClass.walk_data( 73 | session, '.1.3.6.1.2.1.25.1.1', helper)[0][0][:-3] == get_system_uptime()[:-3] 74 | 75 | def test_attempt_walk_data(): 76 | """ 77 | test of the attempt_walk_data function 78 | """ 79 | # try to get data from a not existing host 80 | assert not snmpSessionBaseClass.attempt_walk_data(failSession, '.1')[0] 81 | # check if we receive the system uptime via snmp and compare it with the local uptime from /proc/uptime (except the last digit) 82 | assert snmpSessionBaseClass.attempt_walk_data( 83 | session, '.1.3.6.1.2.1.25.1.1')[0][0][:-3] == get_system_uptime()[:-3] 84 | 85 | def test_state_summary_ok(): 86 | summary_output, long_output = snmpSessionBaseClass.state_summary( 87 | 2, 'summary output', normal_state, helper) 88 | assert 'status: ok' in long_output 89 | assert not summary_output 90 | 91 | def test_state_summary_failed(): 92 | summary_output, long_output = snmpSessionBaseClass.state_summary( 93 | 4, 'summary output', normal_state, helper) 94 | assert 'status: failed' in long_output 95 | assert 'status: failed' in summary_output -------------------------------------------------------------------------------- /test/test_util.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import string 3 | 4 | import pynag.Utils 5 | 6 | def build_threshold_range_string(the_value, the_offset=1, the_inverted_flag=False): 7 | a_threshold_str = str(the_value - the_offset) + ":" + str(the_value + the_offset) 8 | if the_inverted_flag: 9 | a_threshold_str = string.join('@', a_threshold_str) 10 | return a_threshold_str 11 | 12 | def build_threshold_range_strings(the_value=100, the_offset_step=1): 13 | a_warning_threshold = build_threshold_range_string(the_value, the_offset_step) 14 | a_critical_threshold = build_threshold_range_string(the_value, the_offset_step*2) 15 | return a_warning_threshold, a_critical_threshold 16 | 17 | def build_threshold_alert_low_string(the_value, the_offset=0): 18 | a_threshold_str = str(the_value + the_offset) + ":" 19 | return a_threshold_str 20 | 21 | def build_threshold_alert_low_strings(the_value=100, the_offset_step=-1): 22 | a_warning_threshold = build_threshold_alert_low_string(the_value, the_offset_step) 23 | a_critical_threshold = build_threshold_alert_low_string(the_value, the_offset_step*2) 24 | return a_warning_threshold, a_critical_threshold 25 | 26 | def build_threshold_alert_above_string(the_value, the_offset=0, the_zero_flag=False): 27 | a_threshold_str = str(the_value + the_offset) 28 | if not the_zero_flag: 29 | a_threshold_str = "~:" + a_threshold_str 30 | return a_threshold_str 31 | 32 | def build_threshold_alert_above_strings(the_value=100, the_offset_step=1): 33 | a_warning_threshold = build_threshold_alert_above_string(the_value, the_offset_step) 34 | a_critical_threshold = build_threshold_alert_above_string(the_value, the_offset_step*2) 35 | return a_warning_threshold, a_critical_threshold 36 | 37 | def call_and_check(the_plugin_path, the_check_type, thresholds, expected_substring, expected_subsummary): 38 | warning_thres, critical_thres = thresholds 39 | p=subprocess.Popen( 40 | the_plugin_path 41 | + " -H localhost:1234 -t '" + the_check_type + "'" 42 | + " --threshold metric=" + the_check_type + ",warning=" + warning_thres + ",critical=" + critical_thres 43 | , shell=True, stdout=subprocess.PIPE) 44 | a_plugin_return = p.stdout.read() 45 | assert expected_substring in a_plugin_return 46 | assert expected_subsummary in a_plugin_return 47 | 48 | def check_within_range( 49 | the_plugin_path 50 | , the_check_type 51 | , the_expected_value 52 | , the_plugin_summary): 53 | call_and_check(the_plugin_path, the_check_type, build_threshold_range_strings(the_expected_value + 1), "OK - ", the_plugin_summary) 54 | call_and_check(the_plugin_path, the_check_type, build_threshold_range_strings(the_expected_value - 1), "OK - ", the_plugin_summary) 55 | call_and_check(the_plugin_path, the_check_type, build_threshold_range_strings(the_expected_value + 2, ), "Warning - ", the_plugin_summary) 56 | call_and_check(the_plugin_path, the_check_type, build_threshold_range_strings(the_expected_value - 2), "Warning - ", the_plugin_summary) 57 | call_and_check(the_plugin_path, the_check_type, build_threshold_range_strings(the_expected_value + 3, ), "Critical - ", the_plugin_summary) 58 | call_and_check(the_plugin_path, the_check_type, build_threshold_range_strings(the_expected_value - 3), "Critical - ", the_plugin_summary) 59 | 60 | def check_below_threshold( 61 | the_plugin_path 62 | , the_check_type 63 | , the_expected_value 64 | , the_plugin_summary): 65 | call_and_check(the_plugin_path, the_check_type, build_threshold_alert_low_strings(the_expected_value + 1), "OK - ", the_plugin_summary) 66 | call_and_check(the_plugin_path, the_check_type, build_threshold_alert_low_strings(the_expected_value + 2), "Warning - ", the_plugin_summary) 67 | call_and_check(the_plugin_path, the_check_type, build_threshold_alert_low_strings(the_expected_value + 3), "Critical - ", the_plugin_summary) 68 | 69 | def check_above_threshold( 70 | the_plugin_path 71 | , the_check_type 72 | , the_expected_value 73 | , the_plugin_summary): 74 | call_and_check(the_plugin_path, the_check_type, build_threshold_alert_above_strings(the_expected_value - 1), "OK - ", the_plugin_summary) 75 | call_and_check(the_plugin_path, the_check_type, build_threshold_alert_above_strings(the_expected_value - 2), "Warning - ", the_plugin_summary) 76 | call_and_check(the_plugin_path, the_check_type, build_threshold_alert_above_strings(the_expected_value - 3), "Critical - ", the_plugin_summary) 77 | 78 | def check_performance_data( 79 | the_plugin_path 80 | , the_check_type 81 | , the_expected_value): 82 | 83 | ''' 84 | TODO add more checks for the performance data. Eg. check for invalid chars 85 | ''' 86 | warning_thres, critical_thres = build_threshold_range_strings(the_expected_value) 87 | p=subprocess.Popen( 88 | the_plugin_path 89 | + " -H localhost:1234 -t '" + the_check_type + "'" 90 | + " --threshold metric=" + the_check_type + ",warning=" + warning_thres + ",critical=" + critical_thres 91 | , shell=True, stdout=subprocess.PIPE) 92 | 93 | # check if plugin return value contains performance data 94 | # performance data is separated from summary by a pipe character 95 | a_plugin_return = p.stdout.read() 96 | 97 | a_pluginoutput = pynag.Utils.PluginOutput(a_plugin_return) 98 | assert(a_pluginoutput.perfdata) 99 | 100 | def check_value_without_thresholds( 101 | the_plugin_path 102 | , the_check_type 103 | , the_expected_state 104 | , the_plugin_summary): 105 | 106 | # warning_thres, critical_thres = build_threshold_alert_above_strings(the_expected_value-1) 107 | p=subprocess.Popen( 108 | the_plugin_path 109 | + " -H localhost:1234 -t " + the_check_type 110 | , shell=True, stdout=subprocess.PIPE) 111 | a_plugin_return = p.stdout.read() 112 | assert the_expected_state in a_plugin_return 113 | assert the_plugin_summary in a_plugin_return -------------------------------------------------------------------------------- /test/testagent/eventloop.py: -------------------------------------------------------------------------------- 1 | import select 2 | 3 | class EventLoop(object): 4 | """Minimalistic event loop""" 5 | def __init__(self): 6 | self.running = False 7 | self.readfds = [] 8 | self.fd_dict = {} 9 | 10 | def set_default_handler(self, handler): 11 | self.default_handler = handler 12 | 13 | def add_default_fd(self, fd): 14 | self.readfds.append(fd) 15 | 16 | def add_handler(self, fd, handler): 17 | self.readfds.append(fd) 18 | self.fd_dict[fd] = handler 19 | 20 | def stop(self): 21 | self.running = False 22 | 23 | def run(self): 24 | self.running = True 25 | while (self.running): 26 | readable, writable, exceptional = select.select(self.readfds, [], []) 27 | for fd in readable: 28 | if fd in self.fd_dict: 29 | self.fd_dict[fd](self.stop) 30 | else: 31 | self.default_handler(self.stop) 32 | 33 | def is_running(self): 34 | return self.running 35 | -------------------------------------------------------------------------------- /test/testagent/snmp_fd.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import netsnmpapi 3 | 4 | class fd_set(ctypes.Structure): 5 | _fields_ = [('fds_bits', ctypes.c_long * 32)] 6 | 7 | class Timeval(ctypes.Structure): 8 | _fields_ = [("tv_sec", ctypes.c_long), ("tv_usec", ctypes.c_long)] 9 | 10 | def FD_SET(fd, fd_set): 11 | """Set fd in fd_set, where fd can may be in range of 0..FD_SETSIZE-1 (FD_SETSIZE is 1024 on Linux).""" 12 | l64_offset = fd / 64 13 | bit_in_l64_idx = fd % 64; 14 | fd_set.fds_bits[l64_offset] = fd_set.fds_bits[l64_offset] | (2**bit_in_l64_idx) 15 | 16 | def FD_ISSET(fd, fd_set): 17 | """Check if fd is in fd_set.""" 18 | l64_offset = fd / 64 19 | bit_in_l64_idx = fd % 64; 20 | if fd_set.fds_bits[l64_offset] & (2**bit_in_l64_idx) > 0: 21 | return True 22 | return False 23 | 24 | def netsnmp_event_fd(): 25 | """Return each netsnmp file descriptor by number.""" 26 | maxfd = ctypes.c_int(0) 27 | fdset = fd_set() 28 | timeval = Timeval(0, 0) 29 | fakeblock = ctypes.c_int(1) 30 | netsnmpapi.libnsa.snmp_select_info( 31 | ctypes.byref(maxfd), 32 | ctypes.byref(fdset), 33 | ctypes.byref(timeval), 34 | ctypes.byref(fakeblock) 35 | ) 36 | for fd in range(0, maxfd.value): 37 | if FD_ISSET(fd, fdset): 38 | yield fd 39 | --------------------------------------------------------------------------------