Beispiel #1
0
def executeCli():
    # from Nagstamon.Config import (conf,
    # debug_queue)
    from Nagstamon.Config import conf

    from Nagstamon.Servers import (create_server)

    # Initialize global configuration

    from Nagstamon.Objects import (GenericHost)

    # creates new server object from given servername
    server = create_server(conf.servers[conf.cli_args.servername])

    # gets the current default start/endtime from the server (default current time + 2h)
    start_end_time = server.get_start_end(conf.cli_args.hostname)
    default_start_time = start_end_time[0]
    default_end_time = start_end_time[1]
    # gets the default downtime duration from the nagstamon config
    # default_downtime = conf.defaults_downtime_duration_minutes  # never used

    server.GetStatus()

    server.hosts[conf.cli_args.hostname] = GenericHost()
    server.hosts[conf.cli_args.hostname].name = conf.cli_args.hostname
    server.hosts[conf.cli_args.hostname].server = server.name
    server.hosts[conf.cli_args.hostname].site = "monitor"

    fixedType = {"y": True, "n": False}

    info_dict = dict()
    info_dict['host'] = conf.cli_args.hostname
    info_dict['service'] = conf.cli_args.service
    info_dict['author'] = server.username
    info_dict['comment'] = conf.cli_args.comment
    info_dict['fixed'] = fixedType[conf.cli_args.fixed]

    info_dict['start_time'] = checkDefaultValue(conf.cli_args.start_time,
                                                default_start_time)
    info_dict['end_time'] = default_end_time

    info_dict['hours'] = checkDefaultValue(conf.cli_args.hours, 0)
    info_dict['minutes'] = checkDefaultValue(
        conf.cli_args.minutes, conf.defaults_downtime_duration_minutes)
    info_dict['view_name'] = "host"

    info_dict = createEndTime(info_dict)
    # creates output,v which parameter were processed
    if conf.cli_args.output == 'y':
        print('trying to downtime host "' + info_dict['host'] +
              '", with the following parameters:')
        if info_dict['service'] != "":
            print('service: ', info_dict['service'])
        if info_dict['comment'] is not None:
            print('comment: ', info_dict['comment'])
        print('fixed: ', info_dict['fixed'])
        print('start time: ', info_dict['start_time'])
        print('end time: ', info_dict['end_time'])

    server.set_downtime(info_dict)
Beispiel #2
0
def executeCli():
    # from Nagstamon.Config import (conf,
            # debug_queue)
    from Nagstamon.Config import conf

    from Nagstamon.Servers import (create_server)

    # Initialize global configuration

    from Nagstamon.Objects import (GenericHost)

    # creates new server object from given servername
    server = create_server(conf.servers[conf.cli_args.servername])

    # gets the current default start/endtime from the server (default current time + 2h)
    start_end_time = server.get_start_end(conf.cli_args.hostname)
    default_start_time = start_end_time[0]
    default_end_time = start_end_time[1]
    # gets the default downtime duration from the nagstamon config
    # default_downtime = conf.defaults_downtime_duration_minutes  # never used

    server.GetStatus()

    server.hosts[conf.cli_args.hostname] = GenericHost()
    server.hosts[conf.cli_args.hostname].name = conf.cli_args.hostname
    server.hosts[conf.cli_args.hostname].server = server.name
    server.hosts[conf.cli_args.hostname].site = "monitor"

    fixedType = {"y": True, "n": False}

    info_dict = dict()
    info_dict['host'] = conf.cli_args.hostname
    info_dict['service'] = conf.cli_args.service
    info_dict['author'] = server.username
    info_dict['comment'] = conf.cli_args.comment
    info_dict['fixed'] = fixedType[conf.cli_args.fixed]

    info_dict['start_time'] = checkDefaultValue(conf.cli_args.start_time, default_start_time)
    info_dict['end_time'] = default_end_time

    info_dict['hours'] = checkDefaultValue(conf.cli_args.hours, 0)
    info_dict['minutes'] = checkDefaultValue(conf.cli_args.minutes, conf.defaults_downtime_duration_minutes)
    info_dict['view_name'] = "host"

    info_dict = createEndTime(info_dict)
    # creates output,v which parameter were processed
    if conf.cli_args.output == 'y':
        print('trying to downtime host "' + info_dict['host'] + '", with the following parameters:')
        if info_dict['service'] != "":
            print('service: ', info_dict['service'])
        if info_dict['comment'] is not None:
            print('comment: ', info_dict['comment'])
        print('fixed: ', info_dict['fixed'])
        print('start time: ', info_dict['start_time'])
        print('end time: ', info_dict['end_time'])

    server.set_downtime(info_dict)