Execute remote script with NRPE

8.9k views Asked by At

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'
1

There are 1 answers

3
GKV On BEST ANSWER

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