source: people/peter.buschman/backup_monitoring/backmon/commands/check/subcommands/jobs.py@ 1063

Last change on this file since 1063 was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 3.9 KB
Line 
1#!/usr/bin/python26
2###
3### backmon.commands.check.jobs
4###
5
6import sys
7import os
8import os.path
9import glob
10import re
11
12from optparse import OptionParser
13from guppy import hpy
14
15from ....lib import *
16
17from backup_monitoring.debug import *
18from backup_monitoring.math import *
19
20from backup_monitoring.parsing.parsers import bpdbjobs
21
22usage = 'usage: %prog -e [environment] check jobs'
23
24parser = OptionParser(usage=usage)
25
26def run(args, kwargs):
27
28 #
29 # add kwargs to local namespace
30 #
31 for key in kwargs.keys():
32
33 if re.compile('^[A-Z][A-Z_]+$').match(key):
34 exec(key + ' = kwargs[\'' + key + '\']')
35
36 (options, args) = parser.parse_args(args)
37
38 master_feeds = ['nbemmcmd_machinealias_getaliases', 'bpdbjobs_most_columns']
39 media_feeds = [ ]
40
41 if not ENVIRONMENT:
42 ERROR('Must specify backup environment!')
43 sys.exit(1)
44
45 try:
46
47 environment = ENVIRONMENTS[ENVIRONMENT]
48
49 hp = hpy()
50
51 DEBUG('HEAPSIZE=%s' % (heapsize()))
52
53 environment.load_feeds(master=master_feeds, media=media_feeds)
54 environment.parse_jobs()
55
56 DEBUG('HEAPSIZE=%s' % (heapsize()))
57
58 active_backups = 0
59 queued_backups = 0
60 suspended_backups = 0
61 incomplete_backups = 0
62
63 active_restores = 0
64 queued_restores = 0
65 suspended_restores = 0
66 incomplete_restores = 0
67
68 active_duplications = 0
69 queued_duplications = 0
70 suspended_duplications = 0
71 incomplete_duplications = 0
72
73 i = 0
74 j = 0
75
76 for job in environment.jobs:
77
78 i += 1
79
80 if job.jobtype == 'backup':
81
82 if job.active:
83 active_backups += 1
84 continue
85
86 if job.queued:
87 queued_backups += 1
88 continue
89
90 if job.state == 'suspended':
91 suspended_backups += 1
92 continue
93
94 if job.state == 'incomplete':
95 incomplete_backups += 1
96 continue
97
98 if job.jobtype == 'restore':
99
100 if job.active:
101 active_restores += 1
102 continue
103
104 if job.queued:
105 queued_restores += 1
106 continue
107
108 if job.state == 'suspended':
109 suspended_restores += 1
110 continue
111
112 if job.state == 'incomplete':
113 incomplete_restores += 1
114 continue
115
116 if job.jobtype == 'duplication':
117
118 if job.active:
119 active_duplications += 1
120 continue
121
122 if job.queued:
123 queued_duplications += 1
124 continue
125
126 if job.state == 'suspended':
127 suspended_duplications += 1
128 continue
129
130 if job.state == 'incomplete':
131 incomplete_duplications += 1
132 continue
133
134 if i == 0:
135
136 perfdata = 'backups=-1;-1;-1;-1 restores=-1;-1;-1;-1 duplications=-1;-1;-1;-1'
137 print('bpdbjobs output is empty! | %s' % (perfdata))
138 sys.exit(2)
139
140 else:
141
142 perfdata = 'backups=%d;%d;%d;%d restores=%d;%d;%d;%d duplications=%d;%d;%d;%d' % (active_backups, queued_backups, suspended_backups, incomplete_backups, active_restores, queued_restores, suspended_restores, incomplete_restores, active_duplications, queued_duplications, suspended_duplications, incomplete_duplications)
143 print('OK: bpdbjobs contains %d jobs of all types | %s' % (i, perfdata))
144 sys.exit(0)
145
146 except Exception, e:
147
148 raise
149
Note: See TracBrowser for help on using the repository browser.