| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 | 2 # coding: utf-8 |
| 3 | 3 |
| 4 import sys | 4 import sys |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import subprocess | 7 import subprocess |
| 8 import getopt | 8 import getopt |
| 9 import yaml | 9 import yaml |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 monitoringConfig = readMonitoringConfig() | 89 monitoringConfig = readMonitoringConfig() |
| 90 if not monitoringConfig: | 90 if not monitoringConfig: |
| 91 print >>sys.stderr, "Failed to parse monitoring configuration" | 91 print >>sys.stderr, "Failed to parse monitoring configuration" |
| 92 return [[], []] | 92 return [[], []] |
| 93 # Extract hosts and groups from monitoring config | 93 # Extract hosts and groups from monitoring config |
| 94 return processNode(monitoringConfig) | 94 return processNode(monitoringConfig) |
| 95 | 95 |
| 96 def resolveHostList(hosts): | 96 def resolveHostList(hosts): |
| 97 validHosts, validGroups = getValidHosts() | 97 validHosts, validGroups = getValidHosts() |
| 98 if not validHosts: | 98 if not validHosts: |
| 99 print "Warning: No valid hosts found, not validating" | 99 print >>sys.stderr, "Warning: No valid hosts found, not validating" |
| 100 return hosts | 100 return hosts |
| 101 | 101 |
| 102 result = set() | 102 result = set() |
| 103 for param in hosts: | 103 for param in hosts: |
| 104 if param in validGroups: | 104 if param in validGroups: |
| 105 for host in validGroups[param]: | 105 for host in validGroups[param]: |
| 106 if host == '*': | 106 if host == '*': |
| 107 result = result | validHosts | 107 result = result | validHosts |
| 108 else: | 108 else: |
| 109 result.add(host) | 109 result.add(host) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 124 else: | 124 else: |
| 125 subprocess.check_call(command) | 125 subprocess.check_call(command) |
| 126 | 126 |
| 127 if __name__ == "__main__": | 127 if __name__ == "__main__": |
| 128 user, hosts, ignore_errors, args = parseOptions(sys.argv[1:]) | 128 user, hosts, ignore_errors, args = parseOptions(sys.argv[1:]) |
| 129 selectedHosts = resolveHostList(hosts) | 129 selectedHosts = resolveHostList(hosts) |
| 130 if len(selectedHosts) == 0: | 130 if len(selectedHosts) == 0: |
| 131 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' | 131 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' |
| 132 sys.exit(0) | 132 sys.exit(0) |
| 133 for host in selectedHosts: | 133 for host in selectedHosts: |
| 134 print 'Running on %s...' % host | 134 print >>sys.stderr, 'Running on %s...' % host |
|
mathias
2014/08/25 16:21:25
If all logging would be printed to >>stderr (just
Wladimir Palant
2014/08/29 22:11:15
I'm not usually using scripts on the output. And t
| |
| 135 runCommand(user, host, args, ignore_errors=ignore_errors) | 135 runCommand(user, host, args, ignore_errors=ignore_errors) |
| LEFT | RIGHT |