Page 1 of 1

Custom Actions Question

Posted: Fri Nov 06, 2015 11:21 am
by BanditBBS
Ok, so I can guess the custom actions component is running commands as apache, right?

If I am correct on that, what on earth do I need to add to the sudoers file to allow apache to run this command: sudo -i -u nagios /usr/local/nagios/libexec/cdm-update.sh %hostaddress%

Any ideas?

Re: Custom Actions Question

Posted: Fri Nov 06, 2015 1:46 pm
by lmiltchev
Is there any reason why you want to use "sudo -i -u nagios"? I tried the following scenario, which worked OK for me.

In the Actions component:

Code: Select all

/usr/local/nagios/libexec/ping.sh %hostaddress%
ping.sh

Code: Select all

#!/bin/bash

/usr/local/nagios/libexec/check_ping -H $1 -w 100.0,20% -c 500.0,60% -p 3 -4
exit 0

Code: Select all

ll ping.sh
-rwxr-xr-- 1 nagios nagios 97 Nov  6 12:37 ping.sh
I didn't need to modify the sudoers.

Re: Custom Actions Question

Posted: Fri Nov 06, 2015 1:49 pm
by BanditBBS
I need it executed as nagios from nagios' shell. The script does some scp and for key issues it needs to be as nagios.

Re: Custom Actions Question

Posted: Fri Nov 06, 2015 2:23 pm
by scottwilkerson
Something like this?

NEWSCRIPT.sh

Code: Select all

#!/bin/bash
sudo -i -u nagios /usr/local/nagios/libexec/cdm-update.sh $1

visudo

Code: Select all

apache ALL = NOPASSWD:/usr/local/nagios/libexec/NEWSCRIPT.sh *
Add action for

Code: Select all

/usr/local/nagios/libexec/NEWSCRIPT.sh %hostaddress%

Re: Custom Actions Question

Posted: Fri Nov 06, 2015 3:49 pm
by lmiltchev
@BanditBBS
I tried something similar and it worked but this could be a security issue... I can PM you my configs if you want me to.

Re: Custom Actions Question

Posted: Fri Nov 06, 2015 3:52 pm
by BanditBBS
lmiltchev wrote:@BanditBBS
I tried something similar and it worked but this could be a security issue... I can PM you my configs if you want me to.
Please. if it doesn't work for me I'll then post in much more detail what I'm trying to do.

Re: Custom Actions Question

Posted: Mon Nov 09, 2015 10:42 am
by lmiltchev
I sent you a PM.

Re: Custom Actions Question

Posted: Mon Nov 09, 2015 3:15 pm
by BanditBBS
Go ahead and close this up!

Your PM didn't work for me, but it was along the same lines I was going and eventually it would have ended up being security issue. So, instead I created a couple scripts to output the hostaddress to a file and put those as actions. Then I just put a cron job in for nagios that runs every 5 minutes that uses those files.

Thanks for trying though!

Re: Custom Actions Question

Posted: Mon Nov 09, 2015 3:27 pm
by lmiltchev
Your PM didn't work for me, but it was along the same lines I was going and eventually it would have ended up being security issue.
Yeah, as I said, this could be a security issue. I worked for me, but I didn't like the "workaround", either. :)
I am glad you found a better way!
I am locking this topic.