简体   繁体   English

Nagios监控

[英]Nagios Monitoring

Here is the requirement : 这是要求:

I have an application running with python and django. 我有一个运行python和django的应用程序。 The users login details for this application are saving to a mysql table. 该应用程序的用户登录详细信息将保存到mysql表中。 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. 因此,如果两天内没有任何活动,我现在需要在nagios上打印“ CRITICAL”状态,否则在nagios上打印“ OK”状态。 is it possible to implement with nagios? 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. 如果> 2,则将服务设置为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: 您可以创建一个脚本sh来建立与mysql数据库的连接,例如:

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): 然后,您有了las注册日期,因此可以将其用于sh脚本!,例如(非常容易且可扩展):

    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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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