check_send_receive_time: Use a different state file for websockets.

Otherwise, the two Nagios checks will fight over the same state file
if both are in use.
This commit is contained in:
Tim Abbott 2017-02-08 10:54:04 -08:00
parent 5764054bbb
commit 8db13d0bb9
1 changed files with 6 additions and 3 deletions

View File

@ -103,10 +103,13 @@ def report(state, timestamp, msg=None):
now = int(time.time())
if msg is None:
msg = "send time was %s" % (timestamp,)
with open("/var/lib/nagios_state/check_send_receive_state.tmp", 'w') as f:
if options.websocket:
state_file_path = "/var/lib/nagios_state/check_send_receive_websockets_state"
else:
state_file_path = "/var/lib/nagios_state/check_send_receive_state"
with open(state_file_path + ".tmp", 'w') as f:
f.write("%s|%s|%s|%s\n" % (now, states[state], state, msg))
subprocess.check_call(["mv", "/var/lib/nagios_state/check_send_receive_state.tmp",
"/var/lib/nagios_state/check_send_receive_state"])
subprocess.check_call(["mv", state_file_path + ".tmp", state_file_path])
print("%s: %s" % (state, msg))
exit(states[state])