Codebase list debian-goodies / 5397968
Add new --terse command line option to make the script usable by Nagior or similar monitoring script Javier Fernandez-Sanguino 6 years ago
1 changed file(s) with 16 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
8484
8585 # Process options
8686 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"])
8888 except getopt.GetoptError as err:
8989 # print help information and exit:
9090 print(err) # will print something like "option -x not recognized"
9898 onlyPackageFiles = False
9999 # Look for any deleted file
100100 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
102104 machineOutput = False
103105
104106 for o, a in opts:
123125 ignorelist.append(a)
124126 elif o in ("-n", "--nolsof"):
125127 useLsof = False
128 elif o in ("-t", "--terse"):
129 terseOutput = True
126130 else:
127131 assert False, "unhandled option"
128132
153157 else:
154158 toRestart = lsoffilescheck(blacklist = blacklist)
155159
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)
156170
157171 if not machineOutput:
158172 print("Found %d processes using old versions of upgraded files" % len(toRestart))