That’s because you do not in fact have a binary with the name „sudo -u postgres 
/usr/lib/nagios/plugins/check_postgres.pl“. The command attribute is an array 
which contains the arguments which Icinga passes to the execve(2) system call. 
This means that each argument has to be its own array element:

command = [ "sudo", "-u", "postgres", PluginContribDir + "/check_postgres.pl" ]

-----Original Message-----
From: icinga-users <icinga-users-boun...@lists.icinga.org> on behalf of 
"jens.wi...@parcit.de" <jens.wi...@parcit.de>
Reply-To: "icinga-users@lists.icinga.org" <icinga-users@lists.icinga.org>
Date: Monday 22 August 2016 at 12:37
To: "icinga-users@lists.icinga.org" <icinga-users@lists.icinga.org>
Subject: [icinga-users] execute plugins with sudo

    Hi,

    how is it possible to execute plugins with sudo?

    while this works:

    nagios@vm1:~$ sudo -u postgres /usr/lib/nagios/plugins/check_postgres.pl 
--action txn-time -H 127.0.0.1 -c 60 -p 5432 -u postgres
    POSTGRES_TXN_TIME CRITICAL: DB "postgres" (host:127.0.0.1) longest txn: 
9183s (2 hours 33 minutes 3 seconds) PID:15086 database:postgres username:jens 
query:select * from pg_stat_activity ; | time=0.04s transaction_time=9183s;;60

    using this check commend:
    command = [ "sudo -u postgres " + PluginContribDir + "/check_postgres.pl" ]

    icinga2 complains about no such file or directory:

    [2016-08-22 12:09:01 +0200] warning/PluginCheckTask: Check command for 
object 'pg-localhost-5432!pg_txn_time' (PID: 27615, arguments: 'sudo -u 
postgres /usr/lib/nagios/plugins/check_postgres.pl' '--action' 'txn-time' '-H' 
'127.0.0.1'
     '-c' '60' '-p' '5432' '-u' 'postgres') terminated with exit code 128, 
output: execvpe(sudo -u postgres /usr/lib/nagios/plugins/check_postgres.pl) 
failed: No such file or directory
    [2016-08-22 12:10:01 +0200] notice/Process: Running command 'sudo -u 
postgres /usr/lib/nagios/plugins/check_postgres.pl' '--action' 'txn-time' '-H' 
'127.0.0.1' '-c' '60' '-p' '5432' '-u' 'postgres': PID 27973
    [2016-08-22 12:10:01 +0200] notice/Process: PID 27973 ('sudo -u postgres 
/usr/lib/nagios/plugins/check_postgres.pl' '--action' 'txn-time' '-H' 
'127.0.0.1' '-c' '60' '-p' '5432' '-u' 'postgres') terminated with exit code 128
    [2016-08-22 12:10:01 +0200] warning/PluginCheckTask: Check command for 
object 'pg-localhost-5432!pg_txn_time' (PID: 27973, arguments: 'sudo -u 
postgres /usr/lib/nagios/plugins/check_postgres.pl' '--action' 'txn-time' '-H' 
'127.0.0.1'
     '-c' '60' '-p' '5432' '-u' 'postgres') terminated with exit code 128, 
output: execvpe(sudo -u postgres /usr/lib/nagios/plugins/check_postgres.pl) 
failed: No such file or directory

    Jens




-- 
Gunnar Beutner
Senior Developer

NETWAYS GmbH | Deutschherrnstr. 15-19 | D-90429 Nuernberg
Tel: +49 911 92885-0 | Fax: +49 911 92885-77
CEO: Julian Hein, Bernd Erk | AG Nuernberg HRB18461
http://www.netways.de | gunnar.beut...@netways.de

** OSBConf 2016 - September - osbconf.org **
** OSMC 2016 - November - netways.de/osmc **
_______________________________________________
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users

Reply via email to