notification_google_calendar.py
def parse_options():
    """
    Commandline options arguments parsing.
    """

    # build options and help
    version = "%%prog {version}".format(version=__version__)
    parser = OptionParser(version=version)
    parser.add_option(
        "-u", "--username", action="store", dest="username",
        type="string", default="", metavar="RECIPIENT", help="user"
    )
    parser.add_option(
        "-C", "--calendar", metavar="CALENDAR", action="store",
        type="string", dest="calendar", default="", help="google calendar ID"
    )
    parser.add_option(
        "-t", "--timezone", metavar="TIMEZONE", action="store",
        type="string", dest="timezone", default="", help="user timezone"
    )
    parser.add_option(
        "-m", "--message", metavar="MESSAGE", action="store",
        type="string", dest="message", default="", help="message text"
    )
    parser.add_option(
        "-c", "--config", metavar="CONFIG", action="store",
        type="string", dest="config", help="path to config file",
        default="/etc/nagios/notification_google_calendar.ini")
    parser.add_option(
        "-q", "--quiet", metavar="QUIET", action="store_true",
        default=False, dest="quiet", help="be quiet"
    )
    parser.add_option(
        "-g", "--get-google-credentials", metavar="GET-GOOGLE-CREDENTIALS",
        action="store_true", default=False, dest="get_google_credentials",
        help="get google API credentials for user"
    )

    options = parser.parse_args(sys.argv)[0]

    mandatories = ["username", ]
    # check mandatory command line options supplied
    if not options.get_google_credentials:
        mandatories.append("calendar")  # set calendar option required when sending message
        mandatories.append("message")  # set message option required when sending message
        mandatories.append("timezone")  # set timezone option required when sending message
    if not all(options.__dict__[mandatory] for mandatory in mandatories):
        parser.error("Required command line option missing\n")

    return options
def parse_options():
    """
    Commandline options arguments parsing.
    """

    # build options and help
    version = "%%prog {version}".format(version=__version__)
    parser = OptionParser(version=version)
    parser.add_option(
        "-u", "--username", action="store", dest="username",
        type="string", default="", metavar="RECIPIENT", help="user"
    )
    parser.add_option(
        "-C", "--calendar", metavar="CALENDAR", action="store",
        type="string", dest="calendar", default="", help="google calendar ID"
    )
    parser.add_option(
        "-t", "--timezone", metavar="TIMEZONE", action="store",
        type="string", dest="timezone", default="", help="user timezone"
    )
    parser.add_option(
        "-m", "--message", metavar="MESSAGE", action="store",
        type="string", dest="message", default="", help="message text"
    )
    parser.add_option(
        "-c", "--config", metavar="CONFIG", action="store",
        type="string", dest="config", help="path to config file",
        default="/etc/nagios/notification_google_calendar.ini")
    parser.add_option(
        "-q", "--quiet", metavar="QUIET", action="store_true",
        default=False, dest="quiet", help="be quiet"
    )
    parser.add_option(
        "-g", "--get-google-credentials", metavar="GET-GOOGLE-CREDENTIALS",
        action="store_true", default=False, dest="get_google_credentials",
        help="get google API credentials for user"
    )

    options = parser.parse_args(sys.argv)[0]

    mandatories = ["username", ]
    # check mandatory command line options supplied
    if not options.get_google_credentials:
        mandatories.append("calendar")  # set calendar option required when sending message
        mandatories.append("message")  # set message option required when sending message
        mandatories.append("timezone")  # set timezone option required when sending message
    if not all(options.__dict__[mandatory] for mandatory in mandatories):
        parser.error("Required command line option missing\n")

    return options
def parse_options ( ) : # build options and help version = "%%prog {version}" . format ( version = __version__ ) parser = OptionParser ( version = version ) parser . add_option ( "-u" , "--username" , action = "store" , dest = "username" , type = "string" , default = "" , metavar = "RECIPIENT" , help = "user" ) parser . add_option ( "-C" , "--calendar" , metavar = "CALENDAR" , action = "store" , type = "string" , dest = "calendar" , default = "" , help = "google calendar ID" ) parser . add_option ( "-t" , "--timezone" , metavar = "TIMEZONE" , action = "store" , type = "string" , dest = "timezone" , default = "" , help = "user timezone" ) parser . add_option ( "-m" , "--message" , metavar = "MESSAGE" , action = "store" , type = "string" , dest = "message" , default = "" , help = "message text" ) parser . add_option ( "-c" , "--config" , metavar = "CONFIG" , action = "store" , type = "string" , dest = "config" , help = "path to config file" , default = "/etc/nagios/notification_google_calendar.ini" ) parser . add_option ( "-q" , "--quiet" , metavar = "QUIET" , action = "store_true" , default = False , dest = "quiet" , help = "be quiet" ) parser . add_option ( "-g" , "--get-google-credentials" , metavar = "GET-GOOGLE-CREDENTIALS" , action = "store_true" , default = False , dest = "get_google_credentials" , help = "get google API credentials for user" ) options = parser . parse_args ( sys . argv ) [ 0 ] mandatories = [ "username" , ] # check mandatory command line options supplied if not options . get_google_credentials : mandatories . append ( "calendar" ) # set calendar option required when sending message mandatories . append ( "message" ) # set message option required when sending message mandatories . append ( "timezone" ) # set timezone option required when sending message if not all ( options . __dict__ [ mandatory ] for mandatory in mandatories ) : parser . error ( "Required command line option missing\n" ) return options
Commandline options arguments parsing.
Commandline options arguments parsing .