summaryrefslogtreecommitdiffstats
path: root/Monitoring/plugins/check_temper
blob: f2e0fd32bf893795654d12f6cba0bbbf3c226155 (plain)
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import urllib

if len(sys.argv) < 2 or '-h' in sys.argv: 
  print ("?? usage: %s URL [high-val field 1] [high field 2] ..." % sys.argv[0])
  print ("??   Server reply should look like this: '2011-07-11T09:00 50.0 40.0'")
  exit(3)

URL=sys.argv[1]
thresholds=[ float(i) for i in sys.argv[2:]]

ecode=0
try:
  ret = urllib.urlopen(URL).read().split()
  date = ret[0]
  temps = [float(i) for i in ret[1:]]
  print ("** %s : %s" % (date,' '.join([str(i)+"°C" for i in temps])))
  if len(temps) != len(thresholds):
    raise Exception("Number of temps != number of given thresholds")
  for i,temp in enumerate(temps):
    if temp > thresholds[i]:
      print ("!! %.2f°C > %.2f°C (field %d)!" %(temp,thresholds[i],i))
      ecode=2
except Exception,e:
  print("!! Something awful happened: "+str(e))
  exit (1)
if not ecode:
  print ("** Everything is fine!")
exit(ecode)