简体   繁体   中英

Nagios Monitoring

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

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.

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; 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM