notification_google_calendar.py
def parse_config(options):
    """
    Get settings from config file.
    """

    if os.path.exists(options.config):
        config = ConfigParser.ConfigParser()
        try:
            config.read(options.config)
        except Exception, err:
            if not options.quiet:
                sys.stderr.write("ERROR: Config file read {config} error. {err}".format(config=options.config, err=err))
            sys.exit(-1)

        try:
            configdata = {
                "secrets": config.get("GOOGLE", "secrets"),
                "credentials": config.get("nagios-notification-google-calendar", "credentials"),
                "start": config.get("nagios-notification-google-calendar", "start"),
                "end": config.get("nagios-notification-google-calendar", "end"),
                "message": config.get("nagios-notification-google-calendar", "message"),
            }
        except ConfigParser.NoOptionError, err:
            if not options.quiet:
                sys.stderr.write("ERROR: Config file missing option error. {err}\n".format(err=err))
            sys.exit(-1)

        # check mandatory config options supplied
        mandatories = ["secrets", "credentials", "start", "end", "message", ]
        if not all(configdata[mandatory] for mandatory in mandatories):
            if not options.quiet:
                sys.stdout.write("Mandatory config option missing\n")
            sys.exit(0)

        return configdata
    else:
        if not options.quiet:
            sys.stderr.write("ERROR: Config file {config} does not exist\n".format(config=options.config))
        sys.exit(0)
def parse_config(options):
    if os.path.exists(options.config):
        config = ConfigParser.ConfigParser()
        try:
            config.read(options.config)
        except Exception, err:
            if not options.quiet:
                sys.stderr.write("ERROR: Config file read {config} error. {err}".format(config=options.config, err=err))
            sys.exit(-1)

        try:
            configdata = {
                "secrets": config.get("GOOGLE", "secrets"),
                "credentials": config.get("nagios-notification-google-calendar", "credentials"),
                "start": config.get("nagios-notification-google-calendar", "start"),
                "end": config.get("nagios-notification-google-calendar", "end"),
                "message": config.get("nagios-notification-google-calendar", "message"),
            }
        except ConfigParser.NoOptionError, err:
            if not options.quiet:
                sys.stderr.write("ERROR: Config file missing option error. {err}\n".format(err=err))
            sys.exit(-1)

        # check mandatory config options supplied
        mandatories = ["secrets", "credentials", "start", "end", "message", ]
        if not all(configdata[mandatory] for mandatory in mandatories):
            if not options.quiet:
                sys.stdout.write("Mandatory config option missing\n")
            sys.exit(0)

        return configdata
    else:
        if not options.quiet:
            sys.stderr.write("ERROR: Config file {config} does not exist\n".format(config=options.config))
        sys.exit(0)
def parse_config ( options ) : if os . path . exists ( options . config ) : config = ConfigParser . ConfigParser ( ) try : config . read ( options . config ) except Exception , err : if not options . quiet : sys . stderr . write ( "ERROR: Config file read {config} error. {err}" . format ( config = options . config , err = err ) ) sys . exit ( - 1 ) try : configdata = { "secrets" : config . get ( "GOOGLE" , "secrets" ) , "credentials" : config . get ( "nagios-notification-google-calendar" , "credentials" ) , "start" : config . get ( "nagios-notification-google-calendar" , "start" ) , "end" : config . get ( "nagios-notification-google-calendar" , "end" ) , "message" : config . get ( "nagios-notification-google-calendar" , "message" ) , } except ConfigParser . NoOptionError , err : if not options . quiet : sys . stderr . write ( "ERROR: Config file missing option error. {err}\n" . format ( err = err ) ) sys . exit ( - 1 ) # check mandatory config options supplied mandatories = [ "secrets" , "credentials" , "start" , "end" , "message" , ] if not all ( configdata [ mandatory ] for mandatory in mandatories ) : if not options . quiet : sys . stdout . write ( "Mandatory config option missing\n" ) sys . exit ( 0 ) return configdata else : if not options . quiet : sys . stderr . write ( "ERROR: Config file {config} does not exist\n" . format ( config = options . config ) ) sys . exit ( 0 )
Get settings from config file.
Get settings from config file .