-
Notifications
You must be signed in to change notification settings - Fork 21
/
sikteeri_memberships
executable file
·66 lines (54 loc) · 1.72 KB
/
sikteeri_memberships
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os import environ as env
import sys
import urllib2
import json
from urllib2 import HTTPError, URLError
def httpreq(url):
req = urllib2.Request(url)
try:
response = urllib2.urlopen(req)
return (200, response.read())
except HTTPError, e:
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
return (e.code, e.read())
except URLError, e:
print e.reason
return (0, e.reason)
def print_config():
print """graph_args --base 1000 --lower-limit 0
graph_category Sikteeri
graph_info Shows memberships in different statuses
graph_title Memberships in different statuses
graph_vlabel Number in a given status
new.label new
new.min 0
new.info Number of new memberships.
preapproved.label preapproved
preapproved.min 0
preapproved.info Number of preapproved memberships.
approved.label approved
approved.min 0
approved.info Number of approved memberships.
deleted.label deleted
deleted.min 0
deleted.info Number of deleted memberships."""
def main():
if len(sys.argv) > 1:
if sys.argv[1] == 'config':
print_config()
sys.exit(0)
elif 'h' in sys.argv[1]:
print "Set env var URL to the membership/metrics full url, configure TRUSTED_HOSTS correctly and run this script."
sys.exit(0)
code, payload = httpreq(env['URL'])
if code != 200:
print >> sys.stderr, "sikteeri munin plugin ERROR: received HTTP code %i" % code
sys.exit(1)
d = json.loads(payload)
for status in [u'new', u'preapproved', u'approved', u'deleted']:
print "%s.value" % status, d[u'memberships'][status]
if __name__ == '__main__':
main()