This is a Python module wrapping the snmpwalk
command and offering the ability to use Python to:
- execute snmp checks against networked hosts
- execute logic on the output of those checks
This module is specifically designed to be used with Icinga2. It currently supports two primary check methods:
- Virtual Chassis Check
- This check works as follows:
- First, it uses a given host's virtual chassis url (passed as
--virtual_chassis_url
to the script) to get the expected member count for the virtual chassis. This URL comes from thevirtual_chassis__url
property of a given host returned by the/api/dcim/devices/
Netbox REST API endpoint. - Then, it runs an
snmpwalk
command to get the real active member count of the virtual chassis. - It runs a comparison between the expected count (from Netbox) and the real active count (from
snmpwalk
) and generates the appropriate exit status based on the comparison result.- If real active count >= expected count, exit status = 0 (OK)
- If real active count > 0 and < expected count, exit status = 1 (WARNING)
- If real active count == 0, all members down, exit status = 2 (CRITICAL)
- It prints data for time series graphing as
print(f"|active_vc_members={num_lines}")
to record the member count over time, wherenum_lines
is the real active count from thesnmpwalk
- It exits with generated exit status from comparison.
- First, it uses a given host's virtual chassis url (passed as
- Alarm count (count red or yellow alarms)
- For red alarms, it counts the number of results in the
snmpwalk
output that counts the red alarms and sets exit status = 2 (CRITICAL) if the count is greater than 0 (one or more red alarms is critical) - For yellow alarms, it counts the number of results in the
snmpwalk
output that counts the yellow alarms and sets exit status = 1 (WARNING) if the count is greater than 0 (one or more yellow alarms is a warning) - It prints data for time series graphing as
print(f"| alarm_count={count}")
to record the alarm count for a given service check over time, and exits with the generated exit status.
- For red alarms, it counts the number of results in the
- This check works as follows:
To use this with your Icinga2 instance, you will need to:
- Have a functional Netbox instance.
- If you have this, generate an API token to be used by this script or share a token already used by another script/application.
- Have a functional Icinga2 instance, preferably with Icinga Director.
- In Icinga Director, create the following data fields:
- virtual_chassis_url
- snmp_check_type
- snmpv3_oid
- snmp_version
- In Icinga Director, create a Service Template and add those data fields above to the template. Alternatively, add those data fields to an existing Service Template you are already using.
- Create an Import Source and Sync Rule that will synchronize Icinga2 hosts with Netbox using the Netbox API. Use this open source project from digitalocean to achieve this.
- For your sync rule, add the Virtual Chassis URL property highlighted in red in the following image:
- Open Icinga Director > Commands, and add a new command.
- Call it virtual-chassis-snmp-command, and give it the absolute path to the
snmpwalkdriver.py
script that you want to execute. - Open the
Arguments
tab for the command you are creating. - Add the following arguments/values, replacing the red text with your own values that you use for SNMP checks against your hosts:
- Call it virtual-chassis-snmp-command, and give it the absolute path to the
- Open
Icinga Director > Services > Service Apply Rules
- Create a new service apply rule called
VirtualChassis
. You'll search for this name later to check if the apply rule works. - Import the template to which you added the SNMP fields above. You will specify values for these fields for this specific Service Apply Rule.
- Set your "Assign where" option based on the hosts you want to execute virtual chassis checks against
- For the
virtual_chassis_url
field, set the value to$host.vars.virtual_chassis_url$
which will use the value pulled from the Netbox API Sync Rule. - For the
snmp_check_type
field, usevirtual-chassis-netbox-compare
- For the
snmp_version
field, use3
- For the
snmpv3_oid
field, use the OID that is used to check virtual chassis members for your device(s). - Save the service apply rule.
- Create a new service apply rule called
- Open
Icinga Director > Deployments > Render Config > Deploy
- Search for
VirtualChassis
in the global search bar of Icinga Web. If you have any hosts matching your "Assign where" criteria for your apply rule, they will show up in the results. - Verify that the Service Check is running as expected. If not, chances are you may need to modify some of the SNMP arguments you are passing.