Disclaimer: this is most probably not the best way to do this.

Context: I use icinga2 to monitor most of my servers and (home/office) routers. Since icinga collects “perfdata” (performance data) and supports sending that data to Graphite, I then use Grafana to produce graphics of the network usage on my network.

Quick notes for me:

  • generate an ssh key for the nagios user in /var/lib/nagios/.ssh (easier done by doing a sudo to nagios, to avoid having to fix permissions/ownership afterwards).

  • scan known hosts, so that icinga doesn’t get stuck, ex: “ssh-keyscan -H example.bidon.ca » /var/lib/nagios/.ssh/known_hosts”

  • copy the “check_bandwidth” script to the OpenWRT device. (nb: check_bandwidth was written by Benjamin Dos Santos, I did two small changes in my fork to support OpenWRT and output the status in the format required for perfdata).

Define a command in Icinga2 in /etc/icinga2/conf.d/commands.conf (or whatever conf file):

1
2
3
4
5
6
object CheckCommand "bandwidthssh" {
  import "by_ssh"

  vars.by_ssh_command = "/usr/bin/check_bandwidth -i $interface$"
  vars.by_ssh_logname = "root"
}

Define a service in /etc/icinga2/conf.d/services/bandwidth.conf (or whatever conf file) :

1
2
3
4
5
6
7
8
9
apply Service for (iface => config in host.vars.ifaces) {
  import "generic-service"
  check_command = "bandwidthssh"

  vars += config

  # NB: you probably want to use another condition/hostgroup
  assign where "reseaulibre-relays" in host.groups
}

Then define the interfaces that should be monitored for each host:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
object Host "latakia.bidon.ca" {
  import "generic-host"
  groups = [ "reseaulibre-relays" ]
  address6 = "2607:f2c0:xx:yy::1"

  vars.ifaces["if wlan0"] = {
    interface = "wlan0"
  }
  vars.ifaces["if wlan0-1"] = {
    interface = "wlan0-1"
  }
  vars.ifaces["if wlan0-2"] = {
    interface = "wlan0-2"
  }
}