summaryrefslogtreecommitdiffstats
path: root/abs/core/xymon/hobbitadd.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2011-12-07 19:45:02 (GMT)
committerJames Meyer <james.meyer@operamail.com>2011-12-07 19:45:02 (GMT)
commit582455878ef98dfadc0618309686c85b135f7a23 (patch)
treea87b677b96c168524576cf32870487758d0b43ba /abs/core/xymon/hobbitadd.py
parent65b2738ba8a6b80a17c5a2953a29be935b15d18c (diff)
downloadlinhes_pkgbuild-582455878ef98dfadc0618309686c85b135f7a23.zip
linhes_pkgbuild-582455878ef98dfadc0618309686c85b135f7a23.tar.gz
linhes_pkgbuild-582455878ef98dfadc0618309686c85b135f7a23.tar.bz2
xymon: first build, includes both server and client builds.
xymon is a system used to monitor various things about each host. Possible to replace rrdtool and monitorx
Diffstat (limited to 'abs/core/xymon/hobbitadd.py')
-rw-r--r--abs/core/xymon/hobbitadd.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/abs/core/xymon/hobbitadd.py b/abs/core/xymon/hobbitadd.py
new file mode 100644
index 0000000..cb2fbed
--- /dev/null
+++ b/abs/core/xymon/hobbitadd.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+#polls the hobbit server for ghost clients. If it finds ghosts it will make a new bb-hosts file
+#with the new clients.
+#Will not add duplicate clients
+#return code of 0 means a new file was written, anything else is an error or no inserts occured
+import urllib2
+import string
+import sys
+
+
+def readbb():
+ global bblist
+ try:
+ infile = open('/data/srv/xymon/etc/hosts.cfg', 'r')
+ except(IOError), e:
+ print "couldn't open bb-hosts file"
+ sys.exit(1)
+ else:
+ bblist = infile.readlines()
+
+ infile.close()
+
+
+def findghosts():
+ global infile
+ global bblist
+ global ghostitems
+ global numberitems
+ try:
+ f = urllib2.urlopen("http://localhost/xymon/hobbit-cgi/ghostlist.sh?SORT=name&MAXAGE=300&TEXT")
+ except urllib2.HTTPError, e:
+ if e.code != 200:
+ print 'error find ghost list'
+ sys.exit(1)
+ else:
+ ghostitems_full = f.readlines()
+ f.close()
+ ghostitems=[]
+ for i in ghostitems_full:
+ if not i.startswith('127.0.0'):
+ ghostitems.append(i)
+ else:
+ continue
+ numberitems = len(ghostitems)
+
+
+def makenewbb():
+ global bblist
+ global ghostitems
+ global numberitems
+ global numinserts
+ numinserts=0
+ outlist = []
+ for item in bblist:
+ if item not in outlist:
+ outlist.append(item)
+
+ for item in ghostitems:
+ line = item.rstrip()
+ nline = "%s #func" % (line)
+ nline = nline + '\n'
+ if nline not in outlist:
+ outlist.append(nline)
+ print "adding: " + nline
+ numinserts = numinserts + 1
+ if numinserts > 0:
+ outfile = open("/data/srv/xymon/etc/hosts.cfg","w")
+ #outfile = open("/tmp/new-bb","w")
+ for i in outlist:
+ outfile.write(i + '\n' )
+ outfile.close
+
+
+global infile
+global bblist
+global ghostitems
+global numberitems
+global numinserts
+numinserts=0
+readbb()
+findghosts()
+
+
+if numberitems > 0:
+ makenewbb()
+#else:
+# print "No hosts to add"
+
+
+if numinserts < 1:
+ sys.exit(1)
+else:
+ sys.exit(0)
+
+