AM nagios/plc2nagios.py
[monitor.git] / nodesets.py
1 #!/usr/bin/python
2
3 from config import config as cfg
4 import sys
5 import os
6 from sets import Set
7 from optparse import OptionParser
8
9 def main():
10         parser = OptionParser()
11         parser.set_defaults(operation="and",)
12         parser.add_option("", "--operation", dest="operation", metavar="and", 
13                                                 help="""Which operation to perform on the two sets.  (and, or, minus""")
14
15         config = cfg(parser)
16         config.parse_args()
17
18         f1 = config.args[0]
19         f2 = config.args[1]
20
21         s1 = config.getListFromFile(f1)
22         s2 = config.getListFromFile(f2)
23
24         s = nodesets(config.operation, s1, s2)
25
26         if config.operation == "and":
27                 print "Nodes in both sets", len(Set(s1) & Set(s2))
28         elif config.operation == "uniquetoone" or config.operation == "minus":
29                 print "Nodes unique to set 1", len(Set(s1) - Set(s2))
30         elif operation == "or":
31                 print "Union of nodes in both sets", len(Set(s1) | Set(s2))
32
33         for i in s:
34                 print i
35
36
37 def nodesets(operation, s1, s2):
38
39         if operation == "and":
40                 return Set(s1) & Set(s2)
41         elif operation == "uniquetoone" or operation == "minus":
42                 return Set(s1) - Set(s2)
43         elif operation == "or":
44                 return Set(s1) | Set(s2)
45         else:
46                 print "Unknown operation: %s " % operation
47         
48         return []