Permalink
Browse files

added hookbox plugin

  • Loading branch information...
1 parent 1b5c788 commit 545d328a70f9288ee5f41bdab3e4066bb4e7902c @aleszoulek aleszoulek committed Jan 7, 2011
Showing with 62 additions and 0 deletions.
  1. +62 −0 plugins/hookbox
View
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+import os
+import json
+import urllib
+import urllib2
+
+from munin import MuninPlugin
+
+
+
+class HookboxPlugin(MuninPlugin):
+ title = 'hookbox'
+ args = "--base 1000"
+ vlabel = "Y"
+ info = "Subscibed users"
+ scale = False
+
+ def get_channels(self):
+ return os.environ.get('HOOKBOX_CHANNELS', '').split(',')
+
+ def get_url(self):
+ return os.environ.get('HOOKBOX_URL', 'http://localhost:8001/rest')
+
+ def get_secret(self):
+ return os.environ.get('HOOKBOX_SECRET', '')
+
+
+ @property
+ def fields(self):
+ return (
+ (channel, dict(
+ label=channel,
+ info="%s - users" % channel,
+ type="GAUGE",
+ ))
+ for channel in self.get_channels()
+ )
+
+ def get_channel_info(self, channel_name):
+ values = {
+ 'channel_name': channel_name,
+ 'secret': self.get_secret(),
+ }
+ req = urllib2.Request("%s/get_channel_info?%s" % (self.get_url(), urllib.urlencode(values)))
+ resp = urllib2.urlopen(req)
+ return json.loads(resp.read())
+
+ def get_subscribers(self, channel_name):
+ try:
+ return len(self.get_channel_info(channel_name)[1]['subscribers'])
+ except (urllib2.URLError, KeyError), e:
+ return 'U'
+
+ def execute(self):
+ return dict(
+ (channel_name, self.get_subscribers(channel_name))
+ for channel_name in self.get_channels()
+ )
+
+if __name__ == "__main__":
+ HookboxPlugin().run()

0 comments on commit 545d328

Please sign in to comment.