Using arrays in Icinga 2 custom attributes to monitor partitions

Written by - 0 comments

Published on - Listed in Nagios Icinga Monitoring


In the past few weeks I've been heavily involved in Icinga 2, including consulting at an external company and a couple of new setups. Thanks to the custom attributes which exist in Icinga 2, a lot of programmatic possibilities are now possible. 

Today I was wondering, if I was able to use arrays in custom attributes to monitor partitions. Let's take the following example: We have a Linux host which has the following partitions to be monitored: /, /tmp, /var and /srv.

Now I could of course define several service checks for each single partition like this:

# check disk /
object Service "Diskspace /" {
  import "generic-service"
  host_name = "linux-host"
  check_command = "nrpe"
  vars.nrpe_command = "check_disk"
  vars.nrpe_arguments = [ "15%", "5%", "/" ]
}

# check disk /tmp
object Service "Diskspace /tmp" {
  import "generic-service"
  host_name = "linux-host"
  check_command = "nrpe"
  vars.nrpe_command = "check_disk"
  vars.nrpe_arguments = [ "15%", "5%", "/tmp" ]
}

[...] and so on

This works but means that for each host the service checks for each partition needs to be defined. 

Another possibility would be to generally use Apply Rules to "force" all partition checks on all Linux hosts like this:

# check disk /
apply Service "Diskspace /" {
  import "generic-service"
  check_command = "nrpe"
  vars.nrpe_command = "check_disk"
  vars.nrpe_arguments = [ "15%", "5%", "/" ]

  assign where host.address && host.vars.os == "Linux"
  ignore where host.vars.applyignore.linuxdisk.slash == true
}

# check disk /tmp
apply Service "Diskspace /tmp" {
  import "generic-service"
  check_command = "nrpe"
  vars.nrpe_command = "check_disk"
  vars.nrpe_arguments = [ "15%", "5%", "/tmp" ]

  assign where host.address && host.vars.os == "Linux"
  ignore where host.vars.applyignore.linuxdisk.tmp == true
}

[...] and so on

This works, too. But here we have the problem that some partitions (for example /usr) are not a separate partiton to be monitored and therefore would use the same partition as the slash (/) partition. Double-alert and confusion will happen, when a warning or critical threshold is reached. Naah, I don't want that.

With arrays in custom attributes I found another way. With a new custom attribute added in the host definition, the partitions of this particular host can be set:

object Host "linux-host" {
  import "generic-host"
  address = "192.168.1.45"
  vars.os = "Linux"
  # Define partitions of this host:
  vars.partitions = [ "/", "/var", "/srv" ]
}

The apply rule which uses host.vars.partitions then looks like this:

apply Service "Diskspace " for (partition in host.vars.partitions) {
  import "generic-service"
  check_command = "nrpe"
  vars.nrpe_command = "check_disk"
  vars.nrpe_arguments = [ "15%", "5%", partition ]

  assign where host.address && host.vars.os == "Linux"
}

The final result in Icinga 2 looks like this:

Icinga 2 Custom Attributes used for partition checks

Icinga 2 automatically applies three "Diskspace" checks on the host where I only defined /, /var and /srv partitions.
Very nice is also the fact, that the service name is automatically adapted with the partition variable (hence I left an empty space character in "Diskspace ").

There are most likely other possibilities how to handle this, but it's nice to know that multiple choices are there to achieve the goal.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   OpenSearch   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder