Reputation: 115
Here is the requirement :
I have an application running with python and django. The users login details for this application are saving to a mysql table. Once a user login to app, it will be updated on this table. So now I need to print "CRITICAL" status on nagios if there is no activity on the app for two days, otherwise print "OK" status on nagios. is it possible to implement with nagios?
Any help would be appreciated.
Thanks in advance
Upvotes: 0
Views: 424
Reputation: 613
lastupdate=$msql query to count last day update from today date
if lastupdate > 2 ;then
echo 'Your requirement is Completed'
exit 2;
else
echo 'Your requirement is not Completed '
exit 0;
Upvotes: 1
Reputation: 117
You can make an script sh to make a connection to your mysql database, something like:
SELECT date FROM users ORDER DESC BY date LIMIT 1
INTO OUTFILE '/tmp/tmpnagiosusers.txt'
Then you have the las registration date, so you can play with that into your sh script!, for example (very easy and scalable):
today=`date +"%Y-%m-%d")
user=$(mysql -D $MYDB -u $MYUSER -p $MYPASS -se "SELECT COUNT(user_id) FROM users WHERE date >= $today - 2")
if [ $user -lt 1 ];
then
echo 'THere is a problem, you dont have much people registering ($user)' in the last twoo days;
exit 1;
else
echo 'Ok you have $user registrations the last twoo days'
exit 0;
fi
Upvotes: 0
Reputation: 16362
Yes, it's possible. Have a service run a query against the database to count the number of days since the last update. If >2, set the service to CRITICAL.
Upvotes: 1