Add new --terse command line option to make the script usable by Nagior or similar monitoring script
Javier Fernandez-Sanguino
6 years ago
84 | 84 | |
85 | 85 | # Process options |
86 | 86 | try: |
87 | opts, args = getopt.getopt(sys.argv[1:], "hvpamb:i:ne:", ["help", "verbose", "packages", "all", "machine", "blacklist", "ignore", "nolsof", "excludepid"]) | |
87 | opts, args = getopt.getopt(sys.argv[1:], "hvpamb:i:ne:t", ["help", "verbose", "packages", "all", "machine", "blacklist", "ignore", "nolsof", "excludepid", "terse"]) | |
88 | 88 | except getopt.GetoptError as err: |
89 | 89 | # print help information and exit: |
90 | 90 | print(err) # will print something like "option -x not recognized" |
98 | 98 | onlyPackageFiles = False |
99 | 99 | # Look for any deleted file |
100 | 100 | allFiles = False |
101 | # Generate machine parsable output | |
101 | # Generate terse output, disabled by default | |
102 | terseOutput = False | |
103 | # Generate machine parsable output, disabled by default | |
102 | 104 | machineOutput = False |
103 | 105 | |
104 | 106 | for o, a in opts: |
123 | 125 | ignorelist.append(a) |
124 | 126 | elif o in ("-n", "--nolsof"): |
125 | 127 | useLsof = False |
128 | elif o in ("-t", "--terse"): | |
129 | terseOutput = True | |
126 | 130 | else: |
127 | 131 | assert False, "unhandled option" |
128 | 132 | |
153 | 157 | else: |
154 | 158 | toRestart = lsoffilescheck(blacklist = blacklist) |
155 | 159 | |
160 | if terseOutput: | |
161 | # Terse output and exit | |
162 | # Use Nagios exit codes: 0 OK, 1 warning, 2 critical, 3 unknown | |
163 | # we only care for 0 or 1 | |
164 | if len(toRestart): | |
165 | print("%d processes using old versions of upgraded files" % len(toRestart)) | |
166 | sys.exit(1) | |
167 | # Exit with no error if there is nothing to restart | |
168 | print("No processes found using old versions of upgraded files") | |
169 | sys.exit(0) | |
156 | 170 | |
157 | 171 | if not machineOutput: |
158 | 172 | print("Found %d processes using old versions of upgraded files" % len(toRestart)) |