Example #1
0
def do_recheck():
    # Getting lists of informations for the commands
    time_stamp          = request.forms.get('time_stamp', int(time.time()))
    host_name           = request.forms.get('host_name', '')
    service_description = request.forms.get('service_description', '')
    logger.debug("[WS_Arbiter] Timestamp '%s' - host: '%s', service: '%s'" % (time_stamp,
                                                                              host_name,
                                                                              service_description
                                                                             )
                )

    if not host_name:
        abort(400, 'Missing parameter host_name')

    if service_description:
        # SCHEDULE_FORCED_SVC_CHECK;<host_name>;<service_description>;<check_time>
        command = '[%s] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%s\n' % (time_stamp,
                                                                 host_name,
                                                                 service_description,
                                                                 time_stamp)
    else:
        # SCHEDULE_FORCED_HOST_CHECK;<host_name>;<check_time>
        command = '[%s] SCHEDULE_FORCED_HOST_CHECK;%s;%s\n' % (time_stamp,
                                                               host_name,
                                                               time_stamp)

    # We check for auth if it's not anonymously allowed
    check_auth()

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command =  %s" % command)
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #2
0
def get_commands(time_stamps, hosts, services, return_codes, outputs):
    """Composing a command list based on the information received in
    POST request"""

    commands = []

    current_time_stamp = int(time.time())

    def _compose_command(t, h, s, r, o):
        """Simple function to create a command from the inputs"""
        cmd = ""
        if not s or s == "":
            cmd = '[%s] PROCESS_HOST_CHECK_RESULT;%s;%s;%s' % (
                t if t is not None else current_time_stamp, h, r, o)
        else:
            cmd = '[%s] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%s;%s' % (
                t if t is not None else current_time_stamp, h, s, r, o)
        logger.debug("[WS_Arbiter] CMD: %s" % (cmd))
        commands.append(cmd)

    # Trivial case: empty commmand list
    if (return_codes is None or len(return_codes) == 0):
        return commands

    # Sanity check: if we get N return codes, we must have N hosts.
    # The other values could be None
    if (len(return_codes) != len(hosts)):
        logger.error(
            "[WS_Arbiter] number of return codes (%d) does not match number of hosts (%d)"
            % (len(return_codes), len(hosts)))
        abort(400, "number of return codes does not match number of hosts")

    map(_compose_command, time_stamps, hosts, services, return_codes, outputs)
    logger.debug("[WS_Arbiter] received command: %s" % (str(commands)))
    return commands
Example #3
0
def do_change_host_var():
    # Getting lists of informations for the commands
    time_stamp = request.forms.get('time_stamp', int(time.time()))
    host_name = request.forms.get('host_name', '')
    var_name = request.forms.get('var_name', '')
    value = request.forms.get('value', '')
    logger.debug(
        "[WS_Arbiter] Timestamp '%s' - host: '%s', var_name: '%s', value: '%s'"
        % (time_stamp, host_name, var_name, value))

    if not host_name:
        abort(400, 'Missing parameter host_name')
    if not var_name:
        abort(400, 'Missing parameter var_name')

    # We check for auth if it's not anonymously allowed
    check_auth()

    command = '[%s] CHANGE_HOST_VAR;%s;%s;%s\n' % (time_stamp, host_name,
                                                   var_name, value)

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command =  %s" % command)
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #4
0
def do_recheck():
    # Getting lists of informations for the commands
    time_stamp = request.forms.get('time_stamp', int(time.time()))
    host_name = request.forms.get('host_name', '')
    service_description = request.forms.get('service_description', '')
    logger.debug("[WS_Arbiter] Timestamp '%s' - host: '%s', service: '%s'" %
                 (time_stamp, host_name, service_description))

    if not host_name:
        abort(400, 'Missing parameter host_name')

    if service_description:
        # SCHEDULE_FORCED_SVC_CHECK;<host_name>;<service_description>;<check_time>
        command = '[%s] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%s\n' % (
            time_stamp, host_name, service_description, time_stamp)
    else:
        # SCHEDULE_FORCED_HOST_CHECK;<host_name>;<check_time>
        command = '[%s] SCHEDULE_FORCED_HOST_CHECK;%s;%s\n' % (
            time_stamp, host_name, time_stamp)

    # We check for auth if it's not anonymously allowed
    check_auth()

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command =  %s" % command)
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #5
0
def get_commands(time_stamps, hosts, services, return_codes, outputs):
    """Composing a command list based on the information received in
    POST request"""

    commands = []

    current_time_stamp = int(time.time())

    def _compose_command(t, h, s, r, o):
        """Simple function to create a command from the inputs"""
        cmd = ""
        if not s or s == "":
            cmd = '[%s] PROCESS_HOST_CHECK_RESULT;%s;%s;%s' % (t if t is not None else current_time_stamp, h, r, o)
        else:
            cmd = '[%s] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%s;%s' % (t if t is not None else current_time_stamp, h, s, r, o)
        logger.debug("[WS_Arbiter] CMD: %s" % (cmd))
        commands.append(cmd)

    # Trivial case: empty commmand list
    if (return_codes is None or len(return_codes) == 0):
        return commands

    # Sanity check: if we get N return codes, we must have N hosts.
    # The other values could be None
    if (len(return_codes) != len(hosts)):
        logger.error("[WS_Arbiter] number of return codes (%d) does not match number of hosts (%d)" % (len(return_codes), len(hosts)))
        abort(400, "number of return codes does not match number of hosts")

    map(_compose_command, time_stamps, hosts, services, return_codes, outputs)
    logger.debug("[WS_Arbiter] received command: %s" % (str(commands)))
    return commands
Example #6
0
def do_acknowledge():
    # Getting lists of informations for the commands
    action = request.forms.get("action", "add")
    time_stamp = request.forms.get("time_stamp", int(time.time()))
    host_name = request.forms.get("host_name", "")
    service_description = request.forms.get("service_description", "")
    sticky = request.forms.get("sticky", "1")
    notify = request.forms.get("notify", "0")
    persistent = request.forms.get("persistent", "1")
    author = request.forms.get("author", "anonymous")
    comment = request.forms.get("comment", "No comment")
    logger.debug(
        "[WS_Arbiter] Acknowledge %s - host: '%s', service: '%s', comment: '%s'"
        % (action, host_name, service_description, comment)
    )

    if not host_name:
        abort(400, "Missing parameter host_name")

    if action == "add":
        if service_description:
            command = "[%s] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%s;%s;%s;%s;%s\n" % (
                time_stamp,
                host_name,
                service_description,
                sticky,
                notify,
                persistent,
                author,
                comment,
            )
        else:
            command = "[%s] ACKNOWLEDGE_HOST_PROBLEM;%s;%s;%s;%s;%s;%s\n" % (
                time_stamp,
                host_name,
                sticky,
                notify,
                persistent,
                author,
                comment,
            )

    if action == "delete":
        if service_description:
            # REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>
            command = "[%s] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n" % (time_stamp, host_name, service_description)
        else:
            # REMOVE_HOST_ACKNOWLEDGEMENT;<host_name>
            command = "[%s] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n" % (time_stamp, host_name)

    # logger.warning("[WS_Arbiter] command: %s" % (command))
    check_auth()

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command: %s" % str(command))
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #7
0
def do_acknowledge():
    # Getting lists of informations for the commands
    action              = request.forms.get('action', 'add')
    time_stamp          = request.forms.get('time_stamp', int(time.time()))
    host_name           = request.forms.get('host_name', '')
    service_description = request.forms.get('service_description', '')
    sticky              = request.forms.get('sticky', '1')
    notify              = request.forms.get('notify', '0')
    persistent          = request.forms.get('persistent', '1')
    author              = request.forms.get('author', 'anonymous')
    comment             = request.forms.get('comment', 'No comment')
    logger.debug("[WS_Arbiter] Acknowledge %s - host: '%s', service: '%s', comment: '%s'" % (action, host_name, service_description, comment))

    if not host_name:
        abort(400, 'Missing parameter host_name')

    if action == 'add':
        if service_description:
            command = '[%s] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%s;%s;%s;%s;%s\n' % ( time_stamp,
                                                                                host_name,
                                                                                service_description,
                                                                                sticky,
                                                                                notify,
                                                                                persistent,
                                                                                author,
                                                                                comment
                                                                                )
        else:
            command = '[%s] ACKNOWLEDGE_HOST_PROBLEM;%s;%s;%s;%s;%s;%s\n' % (   time_stamp,
                                                                                host_name,
                                                                                sticky,
                                                                                notify,
                                                                                persistent,
                                                                                author,
                                                                                comment
                                                                                )

    if action == 'delete':
        if service_description:
            # REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>
            command = '[%s] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n' % ( time_stamp,
                                                                    host_name,
                                                                    service_description)
        else:
            # REMOVE_HOST_ACKNOWLEDGEMENT;<host_name>
            command = '[%s] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n' % ( time_stamp,
                                                                  host_name)


    # logger.warning("[WS_Arbiter] command: %s" % (command))
    check_auth()

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command: %s" % str(command))
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #8
0
def check_auth():
    """Check for auth if it's not anonymously allowed"""
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')
Example #9
0
def check_auth():
    """Check for auth if it's not anonymously allowed"""
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')
Example #10
0
def do_reload():
    # Getting lists of informations for the commands
    time_stamp = request.forms.get('time_stamp', int(time.time()))
    command = '[%s] RELOAD_CONFIG\n' % time_stamp

    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.warning("[WS_Arbiter] command: %s" % str(command))
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #11
0
def do_reload():
    # Getting lists of informations for the commands
    time_stamp = request.forms.get('time_stamp', int(time.time()))
    command = '[%s] RELOAD_CONFIG\n' % time_stamp

    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.warning("[WS_Arbiter] command: %s" % str(command))
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #12
0
def do_downtime():
    # Getting lists of informations for the commands
    action = request.forms.get('action', 'add')
    time_stamp = request.forms.get('time_stamp', int(time.time()))
    host_name = request.forms.get('host_name', '')
    service_description = request.forms.get('service_description', '')
    start_time = request.forms.get('start_time', int(time.time()))
    end_time = request.forms.get('end_time', int(time.time()))
    # Fixed is 1 for a period between start and end time
    fixed = request.forms.get('fixed', '1')
    # Fixed is 0 (flexible) for a period of duration seconds from start time
    duration = request.forms.get('duration', int('86400'))
    trigger_id = request.forms.get('trigger_id', '0')
    author = request.forms.get('author', 'anonymous')
    comment = request.forms.get('comment', 'No comment')
    logger.debug(
        "[WS_Arbiter] Downtime %s - host: '%s', service: '%s', comment: '%s'" %
        (action, host_name, service_description, comment))

    if not host_name:
        abort(400, 'Missing parameter host_name')

    if action == 'add':
        if service_description:
            # SCHEDULE_SVC_DOWNTIME;<host_name>;<service_description>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
            command = '[%s] SCHEDULE_SVC_DOWNTIME;%s;%s;%s;%s;%s;%s;%s;%s;%s\n' % (
                time_stamp, host_name, service_description, start_time,
                end_time, fixed, trigger_id, duration, author, comment)
        else:
            # SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
            command = '[%s] SCHEDULE_HOST_DOWNTIME;%s;%s;%s;%s;%s;%s;%s;%s\n' % (
                time_stamp, host_name, start_time, end_time, fixed, trigger_id,
                duration, author, comment)

    if action == 'delete':
        if service_description:
            # DEL_ALL_SVC_DOWNTIMES;<host_name>;<service_description>
            command = '[%s] DEL_ALL_SVC_DOWNTIMES;%s;%s\n' % (
                time_stamp, host_name, service_description)
        else:
            # DEL_ALL_SVC_DOWNTIMES;<host_name>
            command = '[%s] DEL_ALL_HOST_DOWNTIMES;%s\n' % (time_stamp,
                                                            host_name)

    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command =  %s" % command)
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #13
0
def do_add_simple_host_dependency():
    # Getting lists of informations for the commands
    time_stamp = request.forms.get('time_stamp', int(time.time()))
    son = request.forms.get('son', '')
    father = request.forms.get('father', '')
    logger.debug("[WS_Arbiter] Timestamp '%s' - son: '%s', father: '%s'" %
                 (time_stamp, son, father))

    if not son:
        abort(400, 'Missing parameter son')
    if not father:
        abort(400, 'Missing parameter father')

    # We check for auth if it's not anonymously allowed
    check_auth()

    command = '[%s] ADD_SIMPLE_HOST_DEPENDENCY;%s;%s\n' % (time_stamp, son,
                                                           father)

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command =  %s" % command)
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #14
0
def do_acknowledge():
    # Getting lists of informations for the commands
    action = request.forms.get('action', 'add')
    time_stamp = request.forms.get('time_stamp', int(time.time()))
    host_name = request.forms.get('host_name', '')
    service_description = request.forms.get('service_description', '')
    sticky = request.forms.get('sticky', '1')
    notify = request.forms.get('notify', '0')
    persistent = request.forms.get('persistent', '1')
    author = request.forms.get('author', 'anonymous')
    comment = request.forms.get('comment', 'No comment')
    logger.debug(
        "[WS_Arbiter] Acknowledge %s - host: '%s', service: '%s', comment: '%s'"
        % (action, host_name, service_description, comment))

    if not host_name:
        abort(400, 'Missing parameter host_name')

    if action == 'add':
        if service_description:
            command = '[%s] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%s;%s;%s;%s;%s\n' % (
                time_stamp, host_name, service_description, sticky, notify,
                persistent, author, comment)
        else:
            command = '[%s] ACKNOWLEDGE_HOST_PROBLEM;%s;%s;%s;%s;%s;%s\n' % (
                time_stamp, host_name, sticky, notify, persistent, author,
                comment)

    if action == 'delete':
        if service_description:
            # REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>
            command = '[%s] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n' % (
                time_stamp, host_name, service_description)
        else:
            # REMOVE_HOST_ACKNOWLEDGEMENT;<host_name>
            command = '[%s] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n' % (time_stamp,
                                                                 host_name)

    # logger.warning("[WS_Arbiter] command: %s" % (command))
    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command: %s" % str(command))
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #15
0
        logger.debug("[WS_Arbiter] service_description_list: %s" % (service_description_list))
        return_code_list = request.forms.getall(key='return_code')
        logger.debug("[WS_Arbiter] return_code_list: %s" % (return_code_list))
        output_list = request.forms.getall(key='output')
        logger.debug("[WS_Arbiter] output_list: %s" % (output_list))
        commands_list = get_commands(time_stamp_list, host_name_list, service_description_list, return_code_list, output_list)
    except Exception, e:
        logger.error("[WS_Arbiter] failed to get the lists: %s" % str(e))
        commands_list = []

    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] commands: %s" % str(sorted(commands_list)))
    for c in sorted(commands_list):
        ext = ExternalCommand(c)
        app.from_q.put(ext)

    # OK here it's ok, it will return a 200 code


def do_restart():
    # Getting lists of informations for the commands
Example #16
0
def do_downtime():
    # Getting lists of informations for the commands
    action = request.forms.get("action", "add")
    time_stamp = request.forms.get("time_stamp", int(time.time()))
    host_name = request.forms.get("host_name", "")
    service_description = request.forms.get("service_description", "")
    start_time = request.forms.get("start_time", int(time.time()))
    end_time = request.forms.get("end_time", int(time.time()))
    # Fixed is 1 for a period between start and end time
    fixed = request.forms.get("fixed", "1")
    # Fixed is 0 (flexible) for a period of duration seconds from start time
    duration = request.forms.get("duration", int("86400"))
    trigger_id = request.forms.get("trigger_id", "0")
    author = request.forms.get("author", "anonymous")
    comment = request.forms.get("comment", "No comment")
    logger.debug(
        "[WS_Arbiter] Downtime %s - host: '%s', service: '%s', comment: '%s'"
        % (action, host_name, service_description, comment)
    )

    if not host_name:
        abort(400, "Missing parameter host_name")

    if action == "add":
        if service_description:
            # SCHEDULE_SVC_DOWNTIME;<host_name>;<service_description>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
            command = "[%s] SCHEDULE_SVC_DOWNTIME;%s;%s;%s;%s;%s;%s;%s;%s;%s\n" % (
                time_stamp,
                host_name,
                service_description,
                start_time,
                end_time,
                fixed,
                trigger_id,
                duration,
                author,
                comment,
            )
        else:
            # SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
            command = "[%s] SCHEDULE_HOST_DOWNTIME;%s;%s;%s;%s;%s;%s;%s;%s\n" % (
                time_stamp,
                host_name,
                start_time,
                end_time,
                fixed,
                trigger_id,
                duration,
                author,
                comment,
            )

    if action == "delete":
        if service_description:
            # DEL_ALL_SVC_DOWNTIMES;<host_name>;<service_description>
            command = "[%s] DEL_ALL_SVC_DOWNTIMES;%s;%s\n" % (time_stamp, host_name, service_description)
        else:
            # DEL_ALL_SVC_DOWNTIMES;<host_name>
            command = "[%s] DEL_ALL_HOST_DOWNTIMES;%s\n" % (time_stamp, host_name)

    # We check for auth if it's not anonymously allowed
    if app.username != "anonymous":
        basic = parse_auth(request.environ.get("HTTP_AUTHORIZATION", ""))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, "Authentication required")
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, "Authentication denied")

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command =  %s" % command)
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #17
0
def do_acknowledge():
    # Getting lists of informations for the commands
    action              = request.forms.get('action', 'add')
    time_stamp          = request.forms.get('time_stamp', int(time.time()))
    host_name           = request.forms.get('host_name', '')
    service_description = request.forms.get('service_description', '')
    sticky              = request.forms.get('sticky', '1')
    notify              = request.forms.get('notify', '0')
    persistent          = request.forms.get('persistent', '1')
    author              = request.forms.get('author', 'anonymous')
    comment             = request.forms.get('comment', 'No comment')
    logger.debug("[WS_Arbiter] Acknowledge %s - host: '%s', service: '%s', comment: '%s'" % (action, host_name, service_description, comment))
 
    if not host_name:
        abort(400, 'Missing parameter host_name')
        
    if action == 'add':
        if service_description:
            command = '[%s] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%s;%s;%s;%s;%s\n' % ( time_stamp,
                                                                                host_name,
                                                                                service_description,
                                                                                sticky,
                                                                                notify,
                                                                                persistent,
                                                                                author,
                                                                                comment
                                                                                )
        else:
            command = '[%s] ACKNOWLEDGE_HOST_PROBLEM;%s;%s;%s;%s;%s;%s\n' % (   time_stamp,
                                                                                host_name,
                                                                                sticky,
                                                                                notify,
                                                                                persistent,
                                                                                author,
                                                                                comment
                                                                                )
        
    if action == 'delete':
        if service_description:
            # REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>
            command = '[%s] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n' % ( time_stamp,
                                                                    host_name,
                                                                    service_description)
        else:
            # REMOVE_HOST_ACKNOWLEDGEMENT;<host_name>
            command = '[%s] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n' % ( time_stamp,
                                                                  host_name)
                                                                                

    # logger.warning("[WS_Arbiter] command: %s" % (command))
    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command: %s" % str(command))
    ext = ExternalCommand(command)
    app.from_q.put(ext)
Example #18
0
        logger.debug("[WS_Arbiter] return_code_list: %s" % (return_code_list))
        output_list = request.forms.getall(key='output')
        logger.debug("[WS_Arbiter] output_list: %s" % (output_list))
        commands_list = get_commands(time_stamp_list, host_name_list,
                                     service_description_list,
                                     return_code_list, output_list)
    except Exception, e:
        logger.error("[WS_Arbiter] failed to get the lists: %s" % str(e))
        commands_list = []

    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] commands: %s" % str(sorted(commands_list)))
    for c in sorted(commands_list):
        ext = ExternalCommand(c)
        app.from_q.put(ext)

    # OK here it's ok, it will return a 200 code


def do_restart():
    # Getting lists of informations for the commands
Example #19
0
def do_downtime():
    # Getting lists of informations for the commands
    action              = request.forms.get('action', 'add')
    time_stamp          = request.forms.get('time_stamp', int(time.time()))
    host_name           = request.forms.get('host_name', '')
    service_description = request.forms.get('service_description', '')
    start_time          = request.forms.get('start_time', int(time.time()))
    end_time            = request.forms.get('end_time', int(time.time()))
    # Fixed is 1 for a period between start and end time
    fixed               = request.forms.get('fixed', '1')
    # Fixed is 0 (flexible) for a period of duration seconds from start time
    duration            = request.forms.get('duration', int('86400'))
    trigger_id          = request.forms.get('trigger_id', '0')
    author              = request.forms.get('author', 'anonymous')
    comment             = request.forms.get('comment', 'No comment')
    logger.debug("[WS_Arbiter] Downtime %s - host: '%s', service: '%s', comment: '%s'" % (action, host_name, service_description, comment))

    if not host_name:
        abort(400, 'Missing parameter host_name')

    if action == 'add':
        if service_description:
            # SCHEDULE_SVC_DOWNTIME;<host_name>;<service_description>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
            command = '[%s] SCHEDULE_SVC_DOWNTIME;%s;%s;%s;%s;%s;%s;%s;%s;%s\n' % ( time_stamp,
                                                                                    host_name,
                                                                                    service_description,
                                                                                    start_time,
                                                                                    end_time,
                                                                                    fixed,
                                                                                    trigger_id,
                                                                                    duration,
                                                                                    author,
                                                                                    comment
                                                                                   )
        else:
            # SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
            command = '[%s] SCHEDULE_HOST_DOWNTIME;%s;%s;%s;%s;%s;%s;%s;%s\n' % (   time_stamp,
                                                                                    host_name,
                                                                                    start_time,
                                                                                    end_time,
                                                                                    fixed,
                                                                                    trigger_id,
                                                                                    duration,
                                                                                    author,
                                                                                    comment
                                                                                )

    if action == 'delete':
        if service_description:
            # DEL_ALL_SVC_DOWNTIMES;<host_name>;<service_description>
            command = '[%s] DEL_ALL_SVC_DOWNTIMES;%s;%s\n' % ( time_stamp,
                                                               host_name,
                                                               service_description)
        else:
            # DEL_ALL_SVC_DOWNTIMES;<host_name>
            command = '[%s] DEL_ALL_HOST_DOWNTIMES;%s\n' % ( time_stamp,
                                                             host_name)


    # We check for auth if it's not anonymously allowed
    if app.username != 'anonymous':
        basic = parse_auth(request.environ.get('HTTP_AUTHORIZATION', ''))
        # Maybe the user not even ask for user/pass. If so, bail out
        if not basic:
            abort(401, 'Authentication required')
        # Maybe he do not give the good credential?
        if basic[0] != app.username or basic[1] != app.password:
            abort(403, 'Authentication denied')

    # Adding commands to the main queue()
    logger.debug("[WS_Arbiter] command =  %s" % command)
    ext = ExternalCommand(command)
    app.from_q.put(ext)