1 | #!/usr/bin/python26
|
---|
2 | ###
|
---|
3 | ### backmon.commands.check.scratch
|
---|
4 | ###
|
---|
5 |
|
---|
6 | import sys
|
---|
7 | import os
|
---|
8 | import os.path
|
---|
9 | import glob
|
---|
10 | import re
|
---|
11 |
|
---|
12 | from optparse import OptionParser
|
---|
13 | from guppy import hpy
|
---|
14 |
|
---|
15 | from ....lib import *
|
---|
16 |
|
---|
17 | from backup_monitoring.debug import *
|
---|
18 | from backup_monitoring.math import *
|
---|
19 |
|
---|
20 | from backup_monitoring.parsing.parsers import vmpool
|
---|
21 | from backup_monitoring.parsing.parsers import vmquery
|
---|
22 | from backup_monitoring.parsing.parsers import bpmedialist
|
---|
23 |
|
---|
24 | usage = 'usage: %prog -e [environment] check scratch [robot_number]'
|
---|
25 |
|
---|
26 | parser = OptionParser(usage=usage)
|
---|
27 |
|
---|
28 | def run(args, kwargs):
|
---|
29 |
|
---|
30 | #
|
---|
31 | # add kwargs to local namespace
|
---|
32 | #
|
---|
33 | for key in kwargs.keys():
|
---|
34 |
|
---|
35 | if re.compile('^[A-Z][A-Z_]+$').match(key):
|
---|
36 | exec(key + ' = kwargs[\'' + key + '\']')
|
---|
37 |
|
---|
38 | (options, args) = parser.parse_args(args)
|
---|
39 |
|
---|
40 | if len(args) == 0:
|
---|
41 | ERROR('No robot number specified!')
|
---|
42 | sys.exit(3)
|
---|
43 |
|
---|
44 | ROBOT_NUMBER = int(args[0])
|
---|
45 |
|
---|
46 | master_feeds = ['nbemmcmd_machinealias_getaliases', 'vmpool', 'vmpool_list_scratch', 'vmquery', 'bpmedialist']
|
---|
47 | media_feeds = [ ]
|
---|
48 |
|
---|
49 | if not ENVIRONMENT:
|
---|
50 | ERROR('Must specify backup environment!')
|
---|
51 | sys.exit(1)
|
---|
52 |
|
---|
53 | try:
|
---|
54 |
|
---|
55 | environment = ENVIRONMENTS[ENVIRONMENT]
|
---|
56 |
|
---|
57 | hp = hpy()
|
---|
58 |
|
---|
59 | DEBUG('HEAPSIZE=%s' % (heapsize()))
|
---|
60 |
|
---|
61 | volume_count = 0
|
---|
62 | scratch_count = 0
|
---|
63 |
|
---|
64 | environment.load_feeds(master=master_feeds, media=media_feeds)
|
---|
65 | environment.parse_pools()
|
---|
66 | environment.parse_scratch()
|
---|
67 | environment.parse_volumes()
|
---|
68 | #environment.parse_media()
|
---|
69 |
|
---|
70 | DEBUG('HEAPSIZE=%s' % (heapsize()))
|
---|
71 |
|
---|
72 | for volume in environment.volumes:
|
---|
73 |
|
---|
74 | if volume.robot_number == ROBOT_NUMBER:
|
---|
75 |
|
---|
76 | volume_count += 1
|
---|
77 |
|
---|
78 | if volume.pool_name == environment.scratch_pool:
|
---|
79 |
|
---|
80 | scratch_count += 1
|
---|
81 |
|
---|
82 | if scratch_count > 0 and volume_count > 0:
|
---|
83 | pct_scratch = float(scratch_count) / float(volume_count) * 100.0
|
---|
84 | else:
|
---|
85 | pct_scratch = 0.0
|
---|
86 |
|
---|
87 | perfdata = 'scratch=%d%%;95;99;0;100' % (pct_scratch)
|
---|
88 | print 'OK: %d scratch volumes out of %d in robot %d | %s' % (scratch_count, volume_count, ROBOT_NUMBER, perfdata)
|
---|
89 |
|
---|
90 | except Exception, e:
|
---|
91 |
|
---|
92 | raise
|
---|
93 |
|
---|
94 | #perfdata = 'scratch=0%;95;99;0;100'
|
---|
95 | #print 'scratch volume monitoring data unavailable! | %s' % (perfdata)
|
---|
96 |
|
---|