I am trying to create a plugin to check the time on a remote system using SNMP and I need to satisfy following condition:
if remote_tz is "True" or remote_tz is not "True" or remote_tz is False:
# body of if statement
And this is my parser:
parser = argparse.ArgumentParser(description='Icinga plugin to check the time on a server using SNMP.')
parser.add_argument('-Z', '--timezone', default="True", help='Timezone of the remote host. This is necessary, because Windows hosts don\'t report the timezone.')
remote_tz = args.timezone
The problem is that when I give -Z option without any argument I am getting the following error check_time_snmp_new1.py: error: argument -Z/--timezone: expected one argument. How to solve this?
[root@server]# ./check_time_snmp_new1.py '-H' '192.168.0.1' '-C' 'xxxx' -Z
usage: check_time_snmp_new1.py [-h] -H HOSTNAME -C COMMUNITY [-S SNMPVER]
[-w WARN] [-c CRITICAL] [-p PORT] [-Z TIMEZONE]
[-d] [-v]
check_time_snmp_new1.py: error: argument -Z/--timezone: expected one argument
[root@server]#
[root@server]# ./check_time_snmp_new1.py '-H' '192.168.0.1' '-C' 'xxxx' -Z 'US/Eastern'
OK - 10.112.8.138 time differs by 0 seconds
[root@server]#
[root@server]# ./check_time_snmp_new1.py '-H' '192.168.0.1' '-C' 'xxxx'
OK - 10.112.8.138 time differs by 0 seconds
[root@server]#
I need the script working with or without -Z and with or without any argument after -Z option. Can anyone help?