forked from fsinf/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathejabberd_availability
executable file
·48 lines (39 loc) · 1.36 KB
/
ejabberd_availability
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
import sys
import time
import MySQLdb
if len(sys.argv) > 1 and sys.argv[1] == 'autoconf':
print 'yes'
sys.exit(0)
# mysql-details
mysql_user = 'pybot'
mysql_pass = 'af1-pybot!dgh'
mysql_host = 'localhost'
mysql_db = 'jabber_watchdog'
# connect to database
db = MySQLdb.connect(mysql_host, mysql_user, mysql_pass, mysql_db)
cursor = db.cursor()
cursor.execute('SELECT server FROM uptime')
servers = cursor.fetchall()
def handle_field(string):
string = string.replace('.', '_')
return string[0:18]
if len(sys.argv) > 1 and sys.argv[1] == 'config':
print """graph_title ejabberd availability
graph_args --base 1000 -l 0
graph_vlabel availability in days
graph_category ejabberd
graph_info This plugin uses a bot from a remote location to test if the server actually works and is reachable over the internet. Testing is done every two minutes."""
for server in servers:
field = handle_field(server[0])
print field + '.label ' + server[0]
print field + '.draw AREA'
sys.exit(0)
else:
for server in servers:
field = handle_field(server[0])
cursor.execute('SELECT last_downtime FROM uptime WHERE server="' + server[0] + '"')
last_downtime = cursor.fetchone()[0]
now = time.time()
uptime = round((now - last_downtime) / 86400, 2)
print field + '.value ' + str(uptime)