Python custom script command & Service defination

Hello ,

We have one custom python script which contain SQL queries, DB server connectivity details and some calculation to fetch Total/failed Transaction data from database. Manually We are able to execute script successfully, but we failed to create command check for this python script in Icinga. Icinga is giving below error.

2021-11-25 10:52:18 +0530] warning/PluginCheckTask: Check command for object 'SERVER-1 Trx Mon' (PID: 146005, arguments: '/usr/lib64/nagios/plugins/trx_mon.py') terminated with exit code 128, output: execvpe(/usr/lib64/nagios/plugins/trx_mon.py) failed: No such file or directory

Manual Execution

[root@Server-ICINGA plugins]# python3 trx_mon.py
OK - Failed transactions within the Threshold of 15 per participant

Command Definition

object CheckCommand "trx_mon" {
  import "plugin-check-command"

  command = [ PluginDir + "/trx_mon.py" ]

   vars.trx_host = "$address$"
}

Service Definition

apply Service "Trx Mon" {
  check_command = "trx_mon"
  check_interval = 1m
  retry_interval = 1m
  vars.grafana_infra_mail = true
  vars.notification["mail"] = {
    /* The UserGroup `icingaadmins` is defined in `users.conf`. */
        groups = [  "infra-team" ]
  }
assign where host.address == "10.13.x.x"
}

[root@INMB1-MON-NewICINGA plugins]# icinga2 --version
icinga2 - The Icinga 2 network monitoring daemon (version: r2.10.2-1)

Copyright (c) 2012-2018 Icinga Development Team (https://icinga.com/)
License GPLv2+: GNU GPL version 2 or later http://gnu.org/licenses/gpl2.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

System information:
Platform: Red Hat Enterprise Linux Server
Platform version: 7.6 (Maipo)
Kernel: Linux
Kernel version: 3.10.0-1160.45.1.el7.x86_64
Architecture: x86_64

Build information:
Compiler: GNU 4.8.5
Build host: unknown

Application information:

General paths:
Config directory: /etc/icinga2
Data directory: /var/lib/icinga2
Log directory: /var/log/icinga2
Cache directory: /var/cache/icinga2
Spool directory: /var/spool/icinga2
Run directory: /run/icinga2

Old paths (deprecated):
Installation root: /usr
Sysconf directory: /etc
Run directory (base): /run
Local state directory: /var

Internal paths:
Package data directory: /usr/share/icinga2
State path: /var/lib/icinga2/icinga2.state
Modified attributes path: /var/lib/icinga2/modified-attributes.conf
Objects path: /var/cache/icinga2/icinga2.debug
Vars path: /var/cache/icinga2/icinga2.vars
PID path: /run/icinga2/icinga2.pid

Can you guide us, how to resolve this issue ?

Thanks

Executing manually means you run your plugins as user root. If your plugins is called by icinga it is executed as user icinga (assuming you use RHEL or CentOS). root and icinga might have different enviroment defined or your shebang does not fit when executed as user icinga.

Hi,

check the file permissions and SELinux (if enabled). It looks like the icinga2 user ist not allowd to access your script

Thanks for quick response.

Yes, I am using RHEL-7 OS and I did manual execution of script with ‘root’ user, I also tried to execute with ‘icinga’ user, but failed due to shell restriction.

[root@INMB1-MON-NewICINGA plugins]# su - icinga -c “python3 trx_mon.py”
This account is currently not available.

My Icinga plugin directory(/usr/lib64/nagios/plugins) is common and having similar permission.

-rwxr-xr-x 1 root root 3.8K Jun 10 2019 check_iis
-rwxr-xr-x 1 root root 2.0K Jun 17 2019 check_https
-rwxr-xr-x 1 root root 5.1K Nov 25 10:55 trx_mon.py

SELinux is in disabled state

[root@INMB1-MON-NewICINGA plugins]# sestatus
SELinux status: disabled

For manual testing I use this command to change to user icinga:

sudo -u icinga bash

1 Like

Hell Friends,

This is strange, but Issue resolved after I converted that python script using dos2unix command.

Thank You so much for all of your support.