Salt Nagios Check Script eine alternative zu NRPE

Download Script: check_by_salt.py

usage: check_by_salt.py [-h] -H HOSTNAME -c PLUGIN [-a ARGUMENTS]

Python script for nagios checks over saltstack. You need to activate the publisher_acl
options for the nagios user and command nagios.run_all in the salt master config file
like this:

publisher_acl:
   nagios:
      - nagios.run_all

The plugin arguments need to start with '+' instead of using '-'.

Usage example: ./check_by_salt.py -H websrv1 -c check_memory -a '+w 10% +c 20%'

optional arguments:
  -h, --help            show this help message and exit
  -H HOSTNAME, --hostname HOSTNAME
                        minion hostname, check the "salt-run manage.up" command to list all minion
                        hostnames.
  -c PLUGIN, --plugin PLUGIN
                        nagios plugin name, check the "salt <minion hostname> nagios.list_plugins"
                        command to list all available nagios plugins.
  -a ARGUMENTS, --arguments ARGUMENTS
                        nagios plugin arguments (optional).

Script ins Verzeichnis /usr/lib/nagios/plugins/ kopieren:

root@localhost:~# cp check_by_salt.py /usr/lib/nagios/plugins/check_by_salt.py

Berechtigung für das Ausführen vergeben:

root@localhost:~# chmod +x /usr/lib/nagios/plugins/check_by_salt.py

Nagios nutzt für die Service-Checks einen dedizierten Benutzer nagios, deshalb muss in die Salt-Master Konfigurationsdatei folgendes angepasst werden:

root@localhost:~# vi /etc/salt/master
# Allow users on the master access to execute specific commands on minions.
# This setting should be treated with care since it opens up execution
# capabilities to non root users. By default this capability is completely
# disabled.
publisher_acl:
#  larry:
#    - test.ping
#    - network.*
    nagios:
      - nagios.run_all
#

Salt Master neustarten:

root@localhost:~# systemctl restat salt-master

Checkcommand kann jetzt in Nagios konfiguriert werden, hier als Beispiel:

$USER1$/check_by_salt.py -H $HOSTNAME$ -c $ARG1$ -a '$ARG2$'

Beispiel Memory Check:

/usr/lib/nagios/plugins/check_by_salt.py -H minion -c check_memory -a '+w 10% +c 20%'
  • Zuletzt geändert: 2020/03/23 14:11