How to monitor network cards on
Yesterday I've been on a task of monitoring network cards of all our servers and infrastructure to check the bandwidth in/out and send alarms based on some criteria. In
Move the script to
Some important usages of the script:
- list interfaces of a specific server (we assume snmp has been installed on the destination server):
The output would be something like below (it can be different in your case):
The interface name is given in front of serial numbers which is
Another mode for the script is
OK, the important part is over and we can list all server network interfaces plus the usage of a specific network interface. In the next part we will explain the
#icinga2 #icinga #nagios #check_nwc_health #network #monitor
Icinga2? (part-1)Yesterday I've been on a task of monitoring network cards of all our servers and infrastructure to check the bandwidth in/out and send alarms based on some criteria. In
Icigna2 we have a library from nagios called check_nwc_health. Download the script from https:// labs.consol.de/nagios/check_nwc_health/index.html.Move the script to
/usr/lib/nagios/plugins on a server that you have installed Icinga2. If you run it all alone you will get some helps that you could be useful.Some important usages of the script:
- list interfaces of a specific server (we assume snmp has been installed on the destination server):
./check_nwc_health --mode list-interfaces --hostname YOUR_TARGET_SERVER_IP --community YOUR_COMMUNITY_STRING
The output would be something like below (it can be different in your case):
000001 lo
000002 Device 1af4:0001 2
000003 Device 1af4:0001 3
000004 docker0
OK - have fun
The interface name is given in front of serial numbers which is
lo, Device 1af4:0001 2 or docker0. These interface names are important and will be used in icinga2 to add network card to hosts.Another mode for the script is
interface-usage that shows in/out bandwidth. The output can be something like follow:OK - interface Device 1af4:0001 2 (alias eth0) usage is in:0.00% (7058.67bit/s) out:0.00% (5603.67bit/s) | 'Device 1af4:0001 2_usage_in'=0%;80;90;0;100 'Device 1af4:0001 2_usage_out'=0%;80;90;0;100 'Device 1af4:0001 2_traffic_in'=7058.67;0;0;0;0 'Device 1af4:0001 2_traffic_out'=5603.67;0;0;0;0
OK, the important part is over and we can list all server network interfaces plus the usage of a specific network interface. In the next part we will explain the
Icinga2 part to add the command and the service to icinga2.#icinga2 #icinga #nagios #check_nwc_health #network #monitor
How to monitor network cards on
Ok for now we have added the plugin to nagios folder and ran some tests on target server's network interfaces. We need to add a command to
In brief it creates a new command called
Now we need to use this command in a service. We have to create a new service which will be used in our hosts configuration sections
Again in brief the service will be applied on hosts that have a variable section of
The final part is to add this service to your desired host. Go to
Add the service like below into your host:
You can go even further like me :) and add these data into
#icinga2 #icinga #service #host #command #nagios #interface #network
Icinga2? (part-2)Ok for now we have added the plugin to nagios folder and ran some tests on target server's network interfaces. We need to add a command to
Icinga2 to use it in service section of Icinga2. To create a new command create a new file in /etc/icinga2/conf.d/commands/check_nwc_command.conf and with the following content:object CheckCommand "YOUR_COMMAND_NAME" {
import "plugin-check-command"
command = [ PluginDir + "/check_nwc_health", "--mode", "interface-usage" ]
arguments = {
"-H" = "$address$"
"-C" = "$community$"
"--name" = "$int$"
}
}In brief it creates a new command called
YOUR_COMMAND_NAME that calls the script check_nwc_health with interface-usage argument to get the bandwidth data.Now we need to use this command in a service. We have to create a new service which will be used in our hosts configuration sections
/etc/icinga2/conf.d/services/if_traffic.conf:apply Service for (display_name => config in host.vars.int) {
import "generic-service"
check_command = "YOUR_COMMAND_NAME"
vars += config
assign where host.vars.int
}Again in brief the service will be applied on hosts that have a variable section of
int in their configuration that we will see a little bit later. YOUR_COMMAND_NAME is the name that we have given in the first part when creating the command.The final part is to add this service to your desired host. Go to
/etc/icinga2/conf.d/hosts and open the file which relates to your host. Host files content start with:object Host "host-54 (Infra)" {Add the service like below into your host:
vars.int["YOUR DISPLAY NAME"] = {
int = "Device 1af4:0001 2"
community = "YOUR SERVER COMMUNITY STRING"
}int is the part that we give the interface name, this should be given from the output of list-interfaces in part-1.You can go even further like me :) and add these data into
Grafana dashboard to have a better understanding of what is happening around you.#icinga2 #icinga #service #host #command #nagios #interface #network
How to get list of network interfaces using nagios?
In nagios plugins there is a script called
Give your host address in
#nagios #network #network_usage
In nagios plugins there is a script called
check_nwc_health that can be used to report network interfaces of a remote server. In order to check interface usage of remote server network cards:cd /usr/lib/nagios/plugins
./check_nwc_health --mode interface-usage -H 172.17.131.12 -C YOUR_COMMUNITY_STRING
Give your host address in
-H section and your community string in -C param.#nagios #network #network_usage
How to check
We assume here that you have a replica set in place. First download the python script for our nagios plugin:
Now the
Create a new file
Create a new file in
This service gets enabled where it finds
#sysadmin #icinga2 #mongodb #replication #replication_lag #nagios_plugin
MongoDB replication lag in Icinga2 and get notified when it is over 15 seconds?We assume here that you have a replica set in place. First download the python script for our nagios plugin:
cd /usr/lib/nagios/plugins
git clone git://github.com/mzupan/nagios-plugin-mongodb.git
Now the
Icinga2 part. You first need to create a command for replication lag check:cd /etc/icinga2/conf.d/commands
Create a new file
replication_lag.conf:object CheckCommand "check_replication_lag" {
import "plugin-check-command"
command = [ PluginDir + "/nagios-plugin-mongodb/check_mongodb.py", "-A", "replication_lag" ]
arguments = {
"-H" = "$mongo_host$"
"-P" = "$mongo_port$"
}
}Create a new file in
services folder called replication_lag.conf:apply Service for (display_name => config in host.vars.replication) {
import "generic-service"
check_command = "check_replication_lag"
vars += config
assign where host.vars.replication
}This service gets enabled where it finds
replication in host config. Now in secondary mongoDB hosts configuration add the below part:vars.replication["Secondary DB"] = {
mongo_host = "slave.example.com"
mongo_port = 27017
}#sysadmin #icinga2 #mongodb #replication #replication_lag #nagios_plugin