handle weird issue
This commit is contained in:
parent
586fac1a07
commit
404d33fc81
|
@ -16,6 +16,9 @@ import dbus
|
|||
|
||||
|
||||
def check_timer(timer_name):
|
||||
if not timer_name.endswith('.timer'):
|
||||
timer_name = timer_name + '.timer'
|
||||
|
||||
try:
|
||||
system_bus = dbus.SystemBus()
|
||||
systemd1 = system_bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
|
||||
|
@ -27,10 +30,16 @@ def check_timer(timer_name):
|
|||
if active_state == 'active':
|
||||
next_elapse = timer_properties.Get('org.freedesktop.systemd1.Timer', 'NextElapseUSecRealtime')
|
||||
|
||||
local_timezone_offset_seconds = time.localtime().tm_gmtoff
|
||||
local_timezone_offset = timedelta(seconds=local_timezone_offset_seconds)
|
||||
local_datetime = datetime.utcfromtimestamp(int(next_elapse) / 1e6) + local_timezone_offset
|
||||
next_elapse_str = local_datetime.strftime("%m-%d-%Y %H:%M")
|
||||
try:
|
||||
local_timezone_offset_seconds = time.localtime().tm_gmtoff
|
||||
local_timezone_offset = timedelta(seconds=local_timezone_offset_seconds)
|
||||
local_datetime = datetime.utcfromtimestamp(int(next_elapse) / 1e6) + local_timezone_offset
|
||||
next_elapse_str = local_datetime.strftime("%m-%d-%Y %H:%M")
|
||||
except Exception as e:
|
||||
print(f'UNKNOWN - exception "{e}"')
|
||||
print('next_elapse:', next_elapse)
|
||||
traceback.print_exc()
|
||||
sys.exit(nagios.STATE_UNKNOWN)
|
||||
|
||||
current_time = time.time() * 1e6 # convert current time to microseconds
|
||||
remaining_time_sec = int((next_elapse - current_time) / 1e6) # convert remaining time to seconds
|
||||
|
@ -52,11 +61,9 @@ def check_timer(timer_name):
|
|||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-t', '--timer', required=True, help='The name of the timer to check.')
|
||||
parser.add_argument('-l', '--last-ran-delta', help='The associated service should have been triggered at least this many seconds ago.')
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.timer.endswith('.timer'):
|
||||
args.timer = args.timer + '.timer'
|
||||
|
||||
try:
|
||||
check_timer(args.timer)
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue