Execute script on located remote host and grab the outout?

  • Version used (icinga2 --version)
    Compiler: GNU 11.2.1
    Build host: runner-hh8q3bz2-project-575-concurrent-0
    OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
  • Operating System and version
    Red Hat Linux 7.9
  • Enabled features (icinga2 feature list)
    Disabled features: compatlog debuglog elasticsearch gelf icingadb influxdb influxdb2 journald livestatus opentsdb perfdata syslog
    Enabled features: api checker command graphite ido-mysql mainlog notification opsgenie

I’m trying to run a script that is located on each of my remote nodes, capture the output, and use the output of either 0 or 1 to determine whether or not an alarm should be sent. I’ve been looking at the Monitoring documentation and I just can’t figure out what is necessary. I’ve Googled this question a dozen times and either my search terms are wrong or “execute remote script Icinga” has never been asked before.

The NRPE agent is installed. I just want my icinga node to be able to call the nrpe agent on server X, have the agent run a script, capture the output, and return the value to Icinga. Is that possible?

Thanks for coming forward with your questions.

Icinga 2 does not use NRPE anymore, but comes with its own agent - Agent Based Monitoring - Icinga 2 - which is just another Icinga 2 installation.[1]

To execute your own script, you need to create a CheckCommand - Monitoring Basics - Icinga 2 - and apply it to the necessary host - Monitoring Basics - Icinga 2.

Please take yourself some time to work through at least the first five chapters of the Icinga 2 documentation, as those will likely address follow up questions.

Btw, RHEL 7 is end of life and there will be no further official Icinga releases for it.


  1. Otherwise, you can use other agents, e.g., SSH - Agent Based Monitoring - Icinga 2 - or maybe checkout SNClient+ if you really need NRPE, GitHub - ConSol-Monitoring/snclient: SNClient+ - Cross platform monitoring agent. ↩︎

Of course you can still execute checks against an NRPE agent with Icinga2, though the Icinga2 agent would be preferred on Windows agents. On linux I would opt for check_by_ssh with publickey auth.

The command is also already pre-defined within the ITL: Icinga Template Library - Icinga 2

You will need your script to return and exit code of 0 (OK), 1 (WARN), 2 (CRIT) or 3 (UNKNOWN) and some form of string output (see “monitoring plugin guidelines” for a more detailed explanation.)

Configure a service template to use the check command nrpe, supply the necessary parameters and apply the service template to the target host(s) to create the service.

When running my command locally, it returns 0. But when running it with nrpe, its returning ‘126$’.
Here’s the command:
AVALUE=/opt/illumio_ven/illumio-ven-ctl connectivity-test; echo $?; echo $AVALUE

I have to run the echo because the command itself doesn’t return a value. Just:
/opt/illumio_ven/illumio-ven-ctl connectivity-test
will not print a value.
Any ideas? I’m assigning the value to AVALUE just to hold the result incase the nrpe command is overriding it.

Why not write a small script that executes the command, get’s the output and then handles it accordingly to what you expect?
And then run that script via nrpe.

If your command is behaving differently when called locally or via nrpe, I assume it is caused by running it with different users. Check what user is owning the nrpe process and run the command with that user locally again.

Regards,
Dirk

Could also be the environment.
Classic if it works if run by hand but fails in a cronjob.