monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Monit and SQL query


From: Charles Pino
Subject: RE: Monit and SQL query
Date: Sun, 16 Sep 2012 22:33:29 +0800

nevermind.  my bad i had a space before   #!/usr/bin/python 


i had it somehow working, but the alerts message / email is somewhat not really nice to look at.


Status failed Service foo 

Date: Sun, 16 Sep 2012 21:12:38
Action: alert
Host: orecx
Description: status failed (1) for /root/mysql.py. Error: 1
.

Your faithful employee,
Monit


my question is. can i change the status failed service to my own message? as well as 
Description: status failed (1) for /root/mysql.py. Error: 1 --  id like to have it say that the db hasnt been any writes in the past 12  hrs etc etc.

thanks in advance for any suggestions.

From: address@hidden
To: address@hidden
Subject: RE: Monit and SQL query
Date: Sun, 16 Sep 2012 19:45:15 +0800

hello all,
 i have tried doing a python script named mysql.py

-------------------------------------------------
 #!/usr/bin/python


import sys,MySQLdb


conn = MySQLdb.connect(host="localhost",user="root", passwd="",db="mydb")
cursor = conn.cursor()
cursor.execute("select hour(timediff(now(),(select timestamp from orksegment order by timestamp desc limit 1)))")
row = cursor.fetchone()

if row < 200:
       sys.exit(0)
 else:
       sys.exit(1)
--------------------------------------------------------
and have this /etc/monit.d/mysqlmonitor

check program foo with path "/root/mysql.py"
       if status !=0  then alert



and i am getting this in my /var/log/monit.log

 Sep 16 19:39:42] error    : 'foo' failed to execute '/root/mysql.py' -- Exec format error

can anyone please help and tell me what i did wrong? 



Date: Tue, 11 Sep 2012 20:36:41 -0400
Subject: Re: Monit and SQL query
From: address@hidden
To: address@hidden

I know this is not exactly what you asked for but a whole proof of concept as to how to use monit for a heartbeat check can be found in http://thinkinginsoftware.blogspot.com/2012/09/monitor-your-mysql-or-mssql-servers.html

So considering you already have a query that returns a unique number (the elapsed time) you can parse such a number with something like the below (note I don't know your query but the idea is basically to concat with a well known string to be able to parse the number later on):
mysql -u user -ppassword -e "select CONCAT('delta',  1)" | grep -v CONCAT | sed 's/\(delta\)\([^ ]*\).*/\2/'

The above will return "1".

Now all you need to do is save that into a variable:
myvar=`the above statement here`

Then exit a different than 0 code (standard in shell scripts to denote there was an error:
if [ $myvar -gt 12 ] then;
  exit 1
fi

I recommend to start your script with:
#!/bin/bash -e

The -e option will make the script fail with exit status != 0 if any command inside the script  fails.


On Tue, Sep 11, 2012 at 8:11 AM, Charles Pino <address@hidden> wrote:
sorry the db is MySQL
and i am trying to read  the difference between the last written record and the current time.
if its been 12 hours already. it should send an alert via monit.

problem is i am not really sure how to grep or an sql result that has different values (not just 1 or 0)

if status != 0 then alert   -- should i still use status?  

sorry im completely new to monit.


Date: Mon, 10 Sep 2012 14:51:42 -0400

Subject: Re: Monit and SQL query
From: address@hidden
To: address@hidden


Build a shell script that:
1. will issue the command to your server (you did not say what kind of sql server you have)
2. will parse the result from the server using for example grep and regex
3. If the result is unexpected use 'exit 1' 
4. Set in monit as Martin said

On Mon, Sep 10, 2012 at 6:34 AM, Charles Pino <address@hidden> wrote:
sql statement is supposed to evaluate if the result is >= to 12 , if true then alert. 

 how do i put that in place of " PROCESS OUTPUT AND RETURN 1 IF FAILED OTHERWISE 0" ??

thanks


From: address@hidden
Subject: Re: Monit and SQL query
Date: Mon, 10 Sep 2012 09:06:11 +0200
To: address@hidden


Hello,

you can use the "check program" to test the exit value of custom script. In this case the script can execute the SQL statement and return error if problem is found.

Script skeleton:
--8<--
#!/bin/bash
/ur/bin/mysql -e "SQL STATEMENT" ... | PROCESS OUTPUT AND RETURN 1 IF FAILED OTHERWISE 0
--8<--

Connection of the script with monit:
--8<--
 check program myscript with path "/usr/local/bin/myscript.sh"
       if status != 0 then alert
--8<--

Regards,
Martin


On Sep 9, 2012, at 4:58 PM, Charles Pino <address@hidden> wrote:

Hello all,
 is it possible to execute and SQL query and have monit execute and alert or something else depending on its response?

 i have a sql query that queries a specific table. of something hasnt been updated in that table for 12 hours. i need to send an alert or whatever. that the table/field hasnt been updated.

please help.

thanks

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


-- To unsubscribe: https://lists.nongnu.org/mailman/listinfo/monit-general

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


-- To unsubscribe: https://lists.nongnu.org/mailman/listinfo/monit-general

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


-- To unsubscribe: https://lists.nongnu.org/mailman/listinfo/monit-general

-- To unsubscribe: https://lists.nongnu.org/mailman/listinfo/monit-general

reply via email to

[Prev in Thread] Current Thread [Next in Thread]