2

You can execute a script if you specify a plugin command on the remote server.
In the example below the plugin command is get_disk:

 command[get_disk]=csript.exe c:\nagios\checks\check_disks_percentage_spave_used.vbs

I would however like NRPE on the remote server to execute a script on the client server, without a plugin command.
On the remote server something like this:

check_nrpe  -H 196.35.132.9 -t 60 -c 'csript.exe c:\\nagios\\checks\\check_disks_percentage_space_used.vbs'
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
fredtma
  • 1,007
  • 2
  • 17
  • 27

1 Answers1

6

You can follow following steps to run a command from nagios to monitor a remote machine

  1. lets just say you have 2 machines,
  2. from where you want to monitor ( will call it master)
  3. to whom u want to monitor ( will call it slave)
  4. assuming you are working in linux and in master machine nagios location is "/usr/local/nagios"
  5. your slave machine is also linux and nrpe installation location is "/usr/local/nagios"
  6. put your script/plugin/executable file in slave machine @ /usr/local/nagios/libexec location.

    e.g. - /usr/local/nagios/libexec/test.sh
    and give it executable permission.
    chmod +x test.sh

    1. edit nrpe.cfg and add the command there as


    vi /usr/local/nagios/etc/nrpe.cfg
    add following line
    command[testScript]=/usr/local/nagios/libexec/test.sh
    telling nrpe to run test.sh when it receives testScript command


8. restart nrpe
9. goto master machine
10. edit commands.cfg

vi /usr/local/nagios/etc/objects/commands.cfg
and add following line

define command{
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
by adding this, now master machine is aware what is check_nrpe command.

  1. add a service

    define service{
    use generic-service
    host_name web-node01
    service_description count number of cmd in remote mc
    check_command check_nrpe!testScript
    }
    now nagios know that it has to call testScript command in slave machine,
    and in slave machine we have defined when received testScript command run 'test.sh'
    from thi s'/usr/local/nagios/libexec' location (point no. 7)

  2. now before trying it from nagios you can directly call the nrpe command to check is everything is working fine by following command

    /usr/local/nagios/libexec/check_nrpe -H slave_IP_Address -c testScript
    P.S. this is exactly same command that nagios will run behind the scene

GKV
  • 864
  • 1
  • 12
  • 25
  • Thanks @GKV, I ended up doing something like that. Had to make the changes on 125 remote (slave) machine – fredtma Jan 08 '15 at 09:19
  • 11. add a service ... but where? That seems to be commonly left out of descriptions. I would think /usr/local/nagois/etc/servers/yourServer.cfg but adding the "define service" block causes nagios service to fail to load in that file causes nagios to fail to restart. – Rick O'Shea Apr 12 '16 at 23:51
  • Up voted for the effort put into the answer. It actually really helped me understand how Nagios works :) – ted-k42 Oct 20 '17 at 09:10