Yes I am trying to figure out how to write a plugin that contains conditional logic in regards to sending an alert if more than one superuser exists on the server. The only thing I have so far is the following command:
awk -F: '{if ($3 < 1) print $0}' < /etc/passwd
which prints --> root0:0:root:/root:/bin/bash
This is close to what I need however I need this to report if the total count is more than one and I have no clue how to convert this into commands
So another words if I ran the same command and it printed the following then send an alert
awk -F: '{if ($3 < 1) print $0}' < /etc/passwd
root0:0:root:/root:/bin/bash
super0:0:super:/super:/bin/bash
-> send alert to Nagios
Any help is appreciated.
Create an alert for more than one superuser on server
-
- Posts: 4
- Joined: Thu Dec 08, 2011 11:41 am
-
- -fno-stack-protector
- Posts: 4366
- Joined: Mon Nov 19, 2012 12:10 pm
Re: Create an alert for more than one superuser on server
Something as simple as piping your current command into "wc -l" to check for total line count should work. If it's greater than 1, return critical, if 1 return OK. When returning, simply use exit(0) or exit(2) for OK and Critical respectively. You probably should take a look at the plugin guidelines for a more detailed description.
http://nagiosplug.sourceforge.net/devel ... lines.html
http://nagiosplug.sourceforge.net/devel ... lines.html
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
-
- Posts: 4
- Joined: Thu Dec 08, 2011 11:41 am
Re: Create an alert for more than one superuser on server
Thank You Sir,
I ended up using the following syntax which works as tested.
#!/bin/bash
count=$(awk -F: '{if ($3 < 1) print $0}' < /etc/passwd | wc -l)
if [ $count -lt 2 ] ; then
echo "OK"
exit 0
elif [ $count=2 ] ; then
echo "CRITICAL - Multiple Superusers"
exit 2
fi
done
I ended up using the following syntax which works as tested.
#!/bin/bash
count=$(awk -F: '{if ($3 < 1) print $0}' < /etc/passwd | wc -l)
if [ $count -lt 2 ] ; then
echo "OK"
exit 0
elif [ $count=2 ] ; then
echo "CRITICAL - Multiple Superusers"
exit 2
fi
done