summaryrefslogtreecommitdiffstats
path: root/Monitoring/nagios/plugins/check_speed
blob: 14a5b612bb85a3850f240e1039987acc834175dd (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
32
33
34
#!/usr/bin/python
# -*- coding: utf-8 -*-
#TODO check_speed is nearly the same as check_speeder, consolidate both scripts, probably by giving HIGH:LOW as params
import sys
import urllib

if len(sys.argv) < 2 or '-h' in sys.argv: 
  print ("?? usage: %s URL [low-mhashes] ..." % sys.argv[0])
  print ("??   Server reply should look like this: '2011-07-11T09:00 400.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]
  speeds = [float(i) for i in ret[1:]]
  print ("** %s : %s Mhashes" % (date,' '.join([str(i) for i in speeds])))
  if len(speeds) != len(thresholds):
    raise Exception("!! Number of speeds != number of given thresholds")
  for i,speed in enumerate(speeds):
    if speed < thresholds[i]:
      print ("!! %.2f Mhash < %.2f Mhash ! (field %d)" %(speed,thresholds[i],i))
      ecode=2
except Exception,e:
  print("!! Something aweful happened: "+str(e))
  exit (1)
#TODO return WARNING if date is too old
if not ecode:
  print ("** Everything is fine!")

exit(ecode)