Révision 051ee8ea
Add Munin ILIAS plugin
| plugins/ilias/ilias_ | ||
|---|---|---|
| 1 |
#!/usr/bin/env python |
|
| 2 |
|
|
| 3 |
# The Plugin needs the following configuration settings |
|
| 4 |
#[ilias_*] |
|
| 5 |
#env.ildbuser ilias |
|
| 6 |
#env.ildbpassword youriliaspasword |
|
| 7 |
#env.ildb ilias |
|
| 8 |
|
|
| 9 |
#%# family=auto |
|
| 10 |
#%# capabilities=autoconf suggest |
|
| 11 |
|
|
| 12 |
import os |
|
| 13 |
import sys |
|
| 14 |
import MySQLdb |
|
| 15 |
import _mysql |
|
| 16 |
class ILIAS(): |
|
| 17 |
title = "ILIAS session" |
|
| 18 |
args = "--base 1000 -l 0" |
|
| 19 |
vlabel = "ilias" |
|
| 20 |
category = "ilias" |
|
| 21 |
|
|
| 22 |
def __init__(self): |
|
| 23 |
self.con = None |
|
| 24 |
self.user = os.environ.get('ildbuser', 'root')
|
|
| 25 |
self.pw = os.environ.get('ildbpassword', '')
|
|
| 26 |
self.ildb = os.environ.get('ildb','ilias')
|
|
| 27 |
|
|
| 28 |
def connectdb(self): |
|
| 29 |
self.con = MySQLdb.connect("localhost", self.user, self.pw,self.ildb)
|
|
| 30 |
self.pluginname = sys.argv[0].split('_')[1]
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
def config_sessions(self): |
|
| 34 |
print("graph_title ILIAS Session")
|
|
| 35 |
print("graph_vlabel ilsessions")
|
|
| 36 |
print("graph_category ILIAS")
|
|
| 37 |
print("ilsessions.label ilSessions")
|
|
| 38 |
|
|
| 39 |
def execute_sessions(self): |
|
| 40 |
cursor = self.con.cursor() |
|
| 41 |
cursor.execute("select count(user_id) from usr_session where `expires` > UNIX_TIMESTAMP( NOW( ) ) AND user_id != 0")
|
|
| 42 |
usrs = cursor.fetchone()[0] |
|
| 43 |
print("ilsessions %s"%(usrs))
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
def config_10minavg(self): |
|
| 47 |
print("graph_title ILIAS 10 avg")
|
|
| 48 |
print("graph_vlabel il10minavg")
|
|
| 49 |
print("graph_category ILIAS")
|
|
| 50 |
print("il10minavg.label 10 min Count")
|
|
| 51 |
|
|
| 52 |
def execute_10minavg(self): |
|
| 53 |
cursor = self.con.cursor() |
|
| 54 |
cursor.execute("select count(user_id) from usr_session where 10 * 60 > UNIX_TIMESTAMP( NOW( ) ) - ctime AND user_id != 0")
|
|
| 55 |
usrs = cursor.fetchone()[0] |
|
| 56 |
print("il10minavg %s"%(usrs))
|
|
| 57 |
|
|
| 58 |
def config_60minavg(self): |
|
| 59 |
print("graph_title ILIAS 60 avg")
|
|
| 60 |
print("graph_vlabel il60minavg")
|
|
| 61 |
print("graph_category ILIAS")
|
|
| 62 |
print("il60minavg.label 60 min Count")
|
|
| 63 |
|
|
| 64 |
def execute_60minavg(self): |
|
| 65 |
cursor = self.con.cursor() |
|
| 66 |
cursor.execute("select count(user_id) from usr_session where 60 * 60 > UNIX_TIMESTAMP( NOW( ) ) - ctime AND user_id != 0")
|
|
| 67 |
usrs = cursor.fetchone()[0] |
|
| 68 |
print("il60minavg %s"%(usrs))
|
|
| 69 |
|
|
| 70 |
def config_total1day(self): |
|
| 71 |
print("graph_title Users in 24h")
|
|
| 72 |
print("graph_vlabel iltotal1day")
|
|
| 73 |
print("graph_category ILIAS")
|
|
| 74 |
print("iltotal1day.label User/24h")
|
|
| 75 |
|
|
| 76 |
def execute_total1day(self): |
|
| 77 |
cursor = self.con.cursor() |
|
| 78 |
cursor.execute("select count(usr_id) FROM `usr_data` WHERE last_login >= DATE_SUB( NOW( ) , INTERVAL 1 DAY )")
|
|
| 79 |
usrs = cursor.fetchone()[0] |
|
| 80 |
print("iltotal1day %s"%(usrs))
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
def run(self): |
|
| 84 |
cmd = ((len(sys.argv) > 1) and sys.argv[1] or None) or "execute" |
|
| 85 |
function = None |
|
| 86 |
if cmd == "execute": |
|
| 87 |
function = "execute" |
|
| 88 |
elif cmd == "config": |
|
| 89 |
function = "config" |
|
| 90 |
if function != None: |
|
| 91 |
self.connectdb() |
|
| 92 |
try: |
|
| 93 |
func = getattr(self, "%s_%s"%(function,self.pluginname)) |
|
| 94 |
except AttributeError: |
|
| 95 |
print 'function not found "%s" (%s)' % ("config_%s"%self.pluginname, "self")
|
|
| 96 |
else: |
|
| 97 |
func() |
|
| 98 |
if self.con: |
|
| 99 |
self.con.close() |
|
| 100 |
if cmd == "suggest": |
|
| 101 |
print ("sessions")
|
|
| 102 |
print ("10minavg")
|
|
| 103 |
print ("60minavg")
|
|
| 104 |
print ("total1day")
|
|
| 105 |
if cmd == "autoconf": |
|
| 106 |
try: |
|
| 107 |
con = MySQLdb.connect("localhost", self.user, self.pw,self.ildb)
|
|
| 108 |
cursor = con.cursor() |
|
| 109 |
cursor.execute("SELECT count(component) FROM il_pluginslot")
|
|
| 110 |
except _mysql.Error, e: |
|
| 111 |
print "no (Error %d: %s)" % (e.args[0], e.args[1]) |
|
| 112 |
else: |
|
| 113 |
print "yes" |
|
| 114 |
sys.exit(0) |
|
| 115 |
|
|
| 116 |
|
|
| 117 |
if __name__ == "__main__": |
|
| 118 |
ILIAS().run() |
|
| 119 |
|
|
Formats disponibles : Unified diff