Basic plugin integration question

I’m on the latest Icinga2 and I can’t find an example of how to run this plugin from my master on remote agents. It runs fine on a remote agent:

# sudo -u icinga /usr/lib64/nagios/plugins/check_ide_smart --help
check_ide_smart v2.3.3 (nagios-plugins 2.3.3)
Nagios feature - 1999 Robert Dale <rdale@digital-mission.com>
(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>
Copyright (c) 1998-2014 Nagios Plugin Development Team
        <devel@nagios-plugins.org>

This plugin checks a local hard drive with the (Linux specific) SMART interface [http://smartlinux.sourceforge.net/smart/index.php].
...
...

On my master, I can’t find the right syntax. Here is my /etc/icinga2/zones.d/master/services.:conf:

apply Service "disk" {
  check_command = "disk"
  command_endpoint = host.vars.agent_endpoint
  assign where host.vars.agent_endpoint
}

apply Service "SMART-disk-check-/dev/sda" {
  check_command = [ "ide_smart" ]
  arguments = {
    "--device" = { value = "/dev/sda" }
  }
  command_endpoint = host.vars.agent_endpoint
  assign where host.vars.agent_endpoint
}

The Service “disk” runs fine and gets the right data from the remote endpoint, but the SMART-disk check has a syntax error and icinga2 won’t start. I’ve looked through the documents and I can’t find a way to run a plugin remotely like this. What am I missing? Thanks

What?

Most oft the time it is easier to identify errors when error messages are shared. Without it I’d assume you didn’t define the command object ide_smart.

BTW: Defining service objects in /etc/icinga2/zones.d/master/services.conf will not work with satellites.

Thanks a lot for your reply - I’m remembering now from when I set this up before the agents have to be configured to run some checks. But, why does the disk monitor work running remotely from the master? Sorry, there’s lots of documentation how to set up distributed monitoring but for some reason I can’t find an example showing my simple scenario.

On my master, I have my agent defined in /etc/icinga2/zones.conf and a hostalive and ‘disk’ service works fine. I have this defined for the agent in my zone, agent1.example.com:

# cat /etc/icinga2/zones.d/agent1.example.com/commands.conf
object CheckCommand "SMART-disk-check-/dev/sda" {
  command = [ "ide_smart" ]
  arguments = {
    "--device" = { value = "/dev/sda" }
  }
}

If I run object list I see the command:

Object 'SMART-disk-check-/dev/sda' of type 'CheckCommand':
  % declared in '/etc/icinga2/zones.d/agent1.example.com/commands.conf', lines 1:0-1:46
  * __name = "SMART-disk-check-/dev/sda"
  * arguments
    % = modified in '/etc/icinga2/zones.d/agent1.example.com/commands.conf', lines 3:3-5:3
    * --device
      * value = "/dev/sda"
  * command = [ "ide_smart" ]
    % = modified in '/etc/icinga2/zones.d/agent1.example.com/commands.conf', lines 2:3-2:27
  * env = null
  * execute
    % = modified in 'methods-itl.conf', lines 19:3-19:23
    * arguments = [ "checkable", "cr", "resolvedMacros", "useResolvedMacros" ]
    * deprecated = false
    * name = "Internal#PluginCheck"
    * side_effect_free = false
    * type = "Function"
  * name = "SMART-disk-check-/dev/sda"
  * package = "_etc"
  * source_location
    * first_column = 0
    * first_line = 1
    * last_column = 46
    * last_line = 1
    * path = "/etc/icinga2/zones.d/agent1.example.com/commands.conf"
  * templates = [ "SMART-disk-check-/dev/sda", "plugin-check-command" ]

I restart icinga2 on my master and agent, but my remote agent isn’t getting the update for the command:

# icinga2 object list --type CheckCommand | grep SMART

What else should I check? The basic distributed monitoring seems to be working fine, with no certifcate errors or anything like that.

—EDIT ----

Never mind, the CheckCommand is showing up on my agent, but it’s not doing anything- it doesn’t show up as a service in the dashboard on my agent.

Object 'SMART-disk-check-/dev/sda' of type 'CheckCommand':
  % declared in '/var/lib/icinga2/api/zones/agent1.example.com/_etc/commands.conf', lines 1:0-1:46
  * __name = "SMART-disk-check-/dev/sda"
  * arguments
    % = modified in '/var/lib/icinga2/api/zones/agent1.example.com/_etc/commands.conf', lines 3:3-5:3
    * --device
      * value = "/dev/sda"
  * command = [ "ide_smart" ]
    % = modified in '/var/lib/icinga2/api/zones/agent1.example.com/_etc/commands.conf', lines 2:3-2:27
  * env = null
  * execute
    % = modified in 'methods-itl.conf', lines 19:3-19:23
    * arguments = [ "checkable", "cr", "resolvedMacros", "useResolvedMacros" ]
    * deprecated = false
    * name = "Internal#PluginCheck"
    * side_effect_free = false
    * type = "Function"
  * name = "SMART-disk-check-/dev/sda"
  * package = "_cluster"
  * source_location
    * first_column = 0
    * first_line = 1
    * last_column = 46
    * last_line = 1
    * path = "/var/lib/icinga2/api/zones/agent1.example.com/_etc/commands.conf"
  * templates = [ "SMART-disk-check-/dev/sda", "plugin-check-command" ]
    % = modified in '/var/lib/icinga2/api/zones/agent1.example.com/_etc/commands.conf', lines 1:0-1:46
    % = modified in 'methods-itl.conf', lines 18:2-18:94
  * timeout = 60
  * type = "CheckCommand"
  * vars = null
  * zone = "agent1.example.com"

And I verified the check runs on my agent:

# sudo -u icinga /usr/lib64/nagios/plugins/check_ide_smart --help
check_ide_smart v2.3.3 (nagios-plugins 2.3.3)

Defining command objects directly for a dedicated agent makes no sense e.g. /etc/icinga2/zones.d/agent1.example.com/commands.conf. This would mean this command can only be used at that agent. Best practice is to define them in global zones which is configured at the master (and all satellites) and all agents. We use two global groups, one for Linux and one for Windows machines.

Thank you, I see what I did wrong, all I had I had to do was this:

[root@icinga master]# pwd
/etc/icinga2/zones.d/master

[root@icinga master]# cat services.conf
apply Service "disk" {
  check_command = "disk"
  vars.disk_partitions = [ "/dev/sda1", "/dev/sdb1" ]
  vars.disk_cfree = 5
  vars.disk_wfree = 10
  command_endpoint = host.vars.agent_endpoint
  assign where host.vars.agent_endpoint
}

apply Service "SMART-disk-check-SSD" {
  check_command = "smart"
  vars.smart_device = [ "/dev/sda", "/dev/sdb", "/dev/sdc", "/dev/sdd" ]
  command_endpoint = host.vars.agent_endpoint
  assign where host.vars.agent_endpoint
}