def parse_status(services):
    # parse the status.dat files listed in the config
    # return the status of the servers in a hash
    for region in services.keys():
        services[region]['warning'] = 0
        services[region]['critical'] = 0
        services[region]['unknown'] = 0
        services[region]['color'] = colors.green
        s = status(services[region]['pulled_statfile'])
        s.parse()
        for service in s.data.get('servicestatus', []):
            if (int(service.get('scheduled_downtime_depth', None)) == 0
                    and int(service.get('problem_has_been_acknowledged',
                                        None)) == 0):
                # get all the 'not OK' services
                if (int(service.get('current_state', None)) == 1):
                    services[region]['warning'] += 1
                elif (int(service.get('current_state', None)) == 2):
                    services[region]['critical'] += 1
                elif (int(service.get('current_state', None)) == 3):
                    services[region]['unknown'] += 1

            if services[region]['critical'] > 0:
                services[region]['color'] = colors.red
            elif services[region]['warning'] > 0:
                services[region]['color'] = colors.yellow

    return services
def parse_status(tempfile):
    # parse the status.dat files listed in the config
    # return the status of the servers in a hash
    warning = 0
    critical = 0
    unknown = 0
    color = "#00ff00" # green
    s = status(tempfile)
    s.parse()
    for service in s.data.get('servicestatus', []):
        if (int(service.get('scheduled_downtime_depth', None)) == 0
                and int(service.get('problem_has_been_acknowledged',
                                    None)) == 0):
            # get all the 'not OK' services
            if (int(service.get('current_state', None)) == 1):
                warning += 1
            elif (int(service.get('current_state', None)) == 2):
                critical += 1
            elif (int(service.get('current_state', None)) == 3):
                unknown += 1
        if critical > 0:
            color = "#ff0000" # red
        elif warning > 0:
            color = "#ffff00"# yellow
    return {'warning': warning, 'critical': critical, 'unknown': unknown, 'color': color}
Beispiel #3
0
def _edit_host(request, c):
    """ This is a helper function to edit_object """
    host = c['my_object']
    try:
        c['command_line'] = host.get_effective_command_line()
    except KeyError:
        c['command_line'] = None
    try:
        c['object_macros'] = host.get_all_macros()
    except KeyError:
        c['object_macros'] = None

    if not 'errors' in c:
        c['errors'] = []

    try:
        c['effective_services'] = sorted(
            host.get_effective_services(), key=lambda x: x.get_description())
    except KeyError as e:
        c['errors'].append(_("Could not find service: %(error)s") % {'error': str(e)})

    try:
        c['effective_hostgroups'] = host.get_effective_hostgroups()
    except KeyError as e:
        c['errors'].append(_("Could not find hostgroup: %(error)s") % {'error': str(e)})

    try:
        c['effective_contacts'] = host.get_effective_contacts()
    except KeyError as e:
        c['errors'].append(_("Could not find contact: %(error)s") % {'error': str(e)})

    try:
        c['effective_contactgroups'] = host.get_effective_contact_groups()
    except KeyError as e:
        c['errors'].append(_("Could not find contact_group: %(error)s") % {'error': str(e)})

    try:
        c['effective_command'] = host.get_effective_check_command()
    except KeyError as e:
        if host.check_command is not None:
            c['errors'].append(_("Could not find check_command: %(error)s") % {'error': str(e)})
        elif host.register != '0':
            c['errors'].append(_("You need to define a check command"))
    try:
        s = status()
        s.parse()
        c['status'] = s.get_hoststatus(host['host_name'])
        current_state = c['status']['current_state']
        if int(current_state) == 0:
            c['status']['text'] = 'UP'
            c['status']['css_label'] = 'label-success'
        else:
            c['status']['text'] = 'DOWN'
            c['status']['css_label'] = 'label-important'
    except Exception:
        pass

    return render_to_response('edit_host.html', c, context_instance=RequestContext(request))
Beispiel #4
0
def _edit_service( request, c):
    """ This is a helper function to edit_object """
    service = c['my_object']
    try:
        c['command_line'] = service.get_effective_command_line()
    except KeyError:
        c['command_line'] = None
    try:
        c['object_macros'] = service.get_all_macros()
    except KeyError:
        c['object_macros'] = None
    # Get the current status from Nagios
    try:
        s = status()
        s.parse()
        c['status'] = s.get_servicestatus(service['host_name'], service['service_description'])
        current_state = c['status']['current_state']
        if current_state == "0":
            c['status']['text'] = 'OK'
            c['status']['css_label'] = 'label-success'
        elif current_state == "1":
            c['status']['text'] = 'Warning'
            c['status']['css_label'] = 'label-warning'
        elif current_state == "2":
            c['status']['text'] = 'Critical'
            c['status']['css_label'] = 'label-important'
        else:
            c['status']['text'] = 'Unknown'
            c['status']['css_label'] = 'label-inverse'
    except Exception:
        pass

    try: c['effective_servicegroups'] = service.get_effective_servicegroups()
    except KeyError, e: c['errors'].append( "Could not find servicegroup: %s" % str(e))

    try: c['effective_contacts'] = service.get_effective_contacts()
    except KeyError, e: c['errors'].append( "Could not find contact: %s" % str(e))

    try: c['effective_contactgroups'] = service.get_effective_contact_groups()
    except KeyError, e: c['errors'].append( "Could not find contact_group: %s" % str(e))

    try: c['effective_hostgroups'] = service.get_effective_hostgroups()
    except KeyError, e: c['errors'].append( "Could not find hostgroup: %s" % str(e))

    try: c['effective_command'] = service.get_effective_check_command()
    except KeyError, e: c['errors'].append( "Could not find check_command: %s" % str(e))

    # For the check_command editor, we inject current check_command and a list of all check_commands
    c['check_command'] = (service.check_command or '').split("!")[0]
    c['command_names'] = map(lambda x: x.get("command_name",''), Model.Command.objects.all)
    if c['check_command'] in (None,'','None'):
        c['check_command'] = ''

    return render_to_response('edit_service.html', c, context_instance = RequestContext(request))
Beispiel #5
0
def _edit_service( request, c):
    """ This is a helper function to edit_object """
    service = c['my_object']
    try:
        c['command_line'] = service.get_effective_command_line()
    except KeyError:
        c['command_line'] = None
    try:
        c['object_macros'] = service.get_all_macros()
    except KeyError:
        c['object_macros'] = None
    # Get the current status from Nagios
    try:
        s = status()
        s.parse()
        c['status'] = s.get_servicestatus(service['host_name'], service['service_description'])
        current_state = c['status']['current_state']
        if current_state == "0":
            c['status']['text'] = 'OK'
            c['status']['css_label'] = 'label-success'
        elif current_state == "1":
            c['status']['text'] = 'Warning'
            c['status']['css_label'] = 'label-warning'
        elif current_state == "2":
            c['status']['text'] = 'Critical'
            c['status']['css_label'] = 'label-important'
        else:
            c['status']['text'] = 'Unknown'
            c['status']['css_label'] = 'label-inverse'
    except Exception:
        pass

    try: c['effective_servicegroups'] = service.get_effective_servicegroups()
    except KeyError, e: c['errors'].append( "Could not find servicegroup: %s" % str(e))

    try: c['effective_contacts'] = service.get_effective_contacts()
    except KeyError, e: c['errors'].append( "Could not find contact: %s" % str(e))

    try: c['effective_contactgroups'] = service.get_effective_contact_groups()
    except KeyError, e: c['errors'].append( "Could not find contact_group: %s" % str(e))

    try: c['effective_hostgroups'] = service.get_effective_hostgroups()
    except KeyError, e: c['errors'].append( "Could not find hostgroup: %s" % str(e))

    try:
        c['effective_command'] = service.get_effective_check_command()
    except KeyError, e:
        if service.check_command is not None:
            c['errors'].append( "Could not find check_command: %s" % str(e))
        elif service.register != '0':
            c['errors'].append( "You need to define a check command")
Beispiel #6
0
def _edit_host( request, c):
    """ This is a helper function to edit_object """
    host = c['my_object']
    try:
        c['command_line'] = host.get_effective_command_line()
    except KeyError:
        c['command_line'] = None
    try:
        c['object_macros'] = host.get_all_macros()
    except KeyError:
        c['object_macros'] = None

    if not c.has_key('errors'): c['errors'] = []

    try: c['effective_services'] = sorted(host.get_effective_services(), key=lambda x: x.get_description())
    except KeyError, e: c['errors'].append( "Could not find service: %s" % str(e))

    try: c['effective_hostgroups'] = host.get_effective_hostgroups()
    except KeyError, e: c['errors'].append( "Could not find hostgroup: %s" % str(e))

    try: c['effective_contacts'] = host.get_effective_contacts()
    except KeyError, e: c['errors'].append( "Could not find contact: %s" % str(e))

    try: c['effective_contactgroups'] = host.get_effective_contact_groups()
    except KeyError, e: c['errors'].append( "Could not find contact_group: %s" % str(e))

    try: c['effective_command'] = host.get_effective_check_command()
    except KeyError, e: pass

    try:
        s = status()
        s.parse()
        c['status'] = s.get_hoststatus(host['host_name'])
        current_state = c['status']['current_state']
        if int(current_state) == 0:
            c['status']['text'] = 'UP'
            c['status']['css_label'] = 'label-success'
        else:
            c['status']['text'] = 'DOWN'
            c['status']['css_label'] = 'label-important'
    except Exception:
        pass

    return render_to_response('edit_host.html', c, context_instance = RequestContext(request))
def parse_status(tempfile):
    # parse the status.dat files listed in the config
    # return the status of the servers in a hash
    warning = 0
    critical = 0
    unknown = 0
    color = "#00ff00"  # green
    s = status(tempfile)
    s.parse()

    critical_msg = ""

    for service in s.data.get('servicestatus', []):
        if (int(service.get('scheduled_downtime_depth', None)) == 0 and int(
                service.get('problem_has_been_acknowledged', None)) == 0):
            # get all the 'not OK' services
            if (int(service.get('current_state', None)) == 1):
                warning += 1
            elif (int(service.get('current_state', None)) == 2):
                critical += 1
                if (int(service.get('notifications_enabled', None)) == 1):
                    critical_msg = (critical_msg + service.get('host_name') +
                                    "\n" + service.get('service_description') +
                                    " \n" +
                                    service.get('plugin_output', None) +
                                    "\n\n")

            elif (int(service.get('current_state', None)) == 3):
                unknown += 1
        if critical > 0:
            color = "#ff0000"  # red
        elif warning > 0:
            color = "#ffff00"  # yellow
    return {
        'warning': warning,
        'critical': critical,
        'unknown': unknown,
        'color': color
    }, critical_msg
Beispiel #8
0
def _edit_service(request, c):
    """ This is a helper function to edit_object """
    service = c['my_object']
    try:
        c['command_line'] = service.get_effective_command_line()
    except KeyError:
        c['command_line'] = None
    try:
        c['object_macros'] = service.get_all_macros()
    except KeyError:
        c['object_macros'] = None
    # Get the current status from Nagios
    try:
        s = status()
        s.parse()
        c['status'] = s.get_servicestatus(service['host_name'],
                                          service['service_description'])
        current_state = c['status']['current_state']
        if current_state == "0":
            c['status']['text'] = 'OK'
            c['status']['css_label'] = 'label-success'
        elif current_state == "1":
            c['status']['text'] = 'Warning'
            c['status']['css_label'] = 'label-warning'
        elif current_state == "2":
            c['status']['text'] = 'Critical'
            c['status']['css_label'] = 'label-important'
        else:
            c['status']['text'] = 'Unknown'
            c['status']['css_label'] = 'label-inverse'
    except Exception:
        pass

    try:
        c['effective_servicegroups'] = service.get_effective_servicegroups()
    except KeyError, e:
        c['errors'].append(
            _("Could not find servicegroup: %(error)s") % {'error': str(e)})
Beispiel #9
0
def _edit_service(request, c):
    """ This is a helper function to edit_object """
    service = c['my_object']
    try:
        c['command_line'] = service.get_effective_command_line()
    except KeyError:
        c['command_line'] = None
    try:
        c['object_macros'] = service.get_all_macros()
    except KeyError:
        c['object_macros'] = None
    # Get the current status from Nagios
    try:
        s = status()
        s.parse()
        c['status'] = s.get_servicestatus(
            service['host_name'], service['service_description'])
        current_state = c['status']['current_state']
        if current_state == "0":
            c['status']['text'] = 'OK'
            c['status']['css_label'] = 'label-success'
        elif current_state == "1":
            c['status']['text'] = 'Warning'
            c['status']['css_label'] = 'label-warning'
        elif current_state == "2":
            c['status']['text'] = 'Critical'
            c['status']['css_label'] = 'label-important'
        else:
            c['status']['text'] = 'Unknown'
            c['status']['css_label'] = 'label-inverse'
    except Exception:
        pass

    try:
        c['effective_servicegroups'] = service.get_effective_servicegroups()
    except KeyError, e:
        c['errors'].append(_("Could not find servicegroup: %(error)s") % {'error': str(e)})
Beispiel #10
0
def _edit_service(request, c):
    """ This is a helper function to edit_object """
    service = c["my_object"]
    try:
        c["command_line"] = service.get_effective_command_line()
    except KeyError:
        c["command_line"] = None
    try:
        c["object_macros"] = service.get_all_macros()
    except KeyError:
        c["object_macros"] = None
    # Get the current status from Nagios
    try:
        s = status()
        s.parse()
        c["status"] = s.get_servicestatus(service["host_name"], service["service_description"])
        current_state = c["status"]["current_state"]
        if current_state == "0":
            c["status"]["text"] = "OK"
            c["status"]["css_label"] = "label-success"
        elif current_state == "1":
            c["status"]["text"] = "Warning"
            c["status"]["css_label"] = "label-warning"
        elif current_state == "2":
            c["status"]["text"] = "Critical"
            c["status"]["css_label"] = "label-important"
        else:
            c["status"]["text"] = "Unknown"
            c["status"]["css_label"] = "label-inverse"
    except Exception:
        pass

    try:
        c["effective_servicegroups"] = service.get_effective_servicegroups()
    except KeyError, e:
        c["errors"].append(_("Could not find servicegroup: %(error)s") % {"error": str(e)})
Beispiel #11
0
        c['effective_contactgroups'] = host.get_effective_contact_groups()
    except KeyError, e:
        c['errors'].append(
            _("Could not find contact_group: %(error)s") % {'error': str(e)})

    try:
        c['effective_command'] = host.get_effective_check_command()
    except KeyError, e:
        if host.check_command is not None:
            c['errors'].append(
                _("Could not find check_command: %(error)s") %
                {'error': str(e)})
        elif host.register != '0':
            c['errors'].append(_("You need to define a check command"))
    try:
        s = status()
        s.parse()
        c['status'] = s.get_hoststatus(host['host_name'])
        current_state = c['status']['current_state']
        if int(current_state) == 0:
            c['status']['text'] = 'UP'
            c['status']['css_label'] = 'label-success'
        else:
            c['status']['text'] = 'DOWN'
            c['status']['css_label'] = 'label-important'
    except Exception:
        pass

    return render_to_response('edit_host.html',
                              c,
                              context_instance=RequestContext(request))
Beispiel #12
0
        c['errors'].append(_("Could not find contact: %(error)s") % {'error': str(e)})

    try:
        c['effective_contactgroups'] = host.get_effective_contact_groups()
    except KeyError, e:
        c['errors'].append(_("Could not find contact_group: %(error)s") % {'error': str(e)})

    try:
        c['effective_command'] = host.get_effective_check_command()
    except KeyError, e:
        if host.check_command is not None:
            c['errors'].append(_("Could not find check_command: %(error)s") % {'error': str(e)})
        elif host.register != '0':
            c['errors'].append(_("You need to define a check command"))
    try:
        s = status()
        s.parse()
        c['status'] = s.get_hoststatus(host['host_name'])
        current_state = c['status']['current_state']
        if int(current_state) == 0:
            c['status']['text'] = 'UP'
            c['status']['css_label'] = 'label-success'
        else:
            c['status']['text'] = 'DOWN'
            c['status']['css_label'] = 'label-important'
    except Exception:
        pass

    return render_to_response('edit_host.html', c, context_instance=RequestContext(request))

Beispiel #13
0
def _edit_service(request, c):
    """ This is a helper function to edit_object """
    service = c['my_object']
    try:
        c['command_line'] = service.get_effective_command_line()
    except KeyError:
        c['command_line'] = None
    try:
        c['object_macros'] = service.get_all_macros()
    except KeyError:
        c['object_macros'] = None
    # Get the current status from Nagios
    try:
        s = status()
        s.parse()
        c['status'] = s.get_servicestatus(
            service['host_name'], service['service_description'])
        current_state = c['status']['current_state']
        if current_state == "0":
            c['status']['text'] = 'OK'
            c['status']['css_label'] = 'label-success'
        elif current_state == "1":
            c['status']['text'] = 'Warning'
            c['status']['css_label'] = 'label-warning'
        elif current_state == "2":
            c['status']['text'] = 'Critical'
            c['status']['css_label'] = 'label-important'
        else:
            c['status']['text'] = 'Unknown'
            c['status']['css_label'] = 'label-inverse'
    except Exception:
        pass

    try:
        c['effective_servicegroups'] = service.get_effective_servicegroups()
    except KeyError as e:
        c['errors'].append(_("Could not find servicegroup: %(error)s") % {'error': str(e)})

    try:
        c['effective_contacts'] = service.get_effective_contacts()
    except KeyError as e:
        c['errors'].append(_("Could not find contact: %(error)s") % {'error': str(e)})

    try:
        c['effective_contactgroups'] = service.get_effective_contact_groups()
    except KeyError as e:
        c['errors'].append(_("Could not find contact_group: %(error)s") % {'error': str(e)})

    try:
        c['effective_hostgroups'] = service.get_effective_hostgroups()
    except KeyError as e:
        c['errors'].append(_("Could not find hostgroup: %(error)s") % {'error': str(e)})

    try:
        c['effective_command'] = service.get_effective_check_command()
    except KeyError as e:
        if service.check_command is not None:
            c['errors'].append(_("Could not find check_command: %(error)s") % {'error': str(e)})
        elif service.register != '0':
            c['errors'].append(_("You need to define a check command"))

    # For the check_command editor, we inject current check_command and a list
    # of all check_commands
    c['check_command'] = (service.check_command or '').split("!")[0]
    c['command_names'] = [x.get("command_name", '') for x in Model.Command.objects.all]
    if c['check_command'] in (None, '', 'None'):
        c['check_command'] = ''

    if service.hostgroup_name and service.hostgroup_name != 'null':
        c['errors'].append(_("This Service is applied to every host in hostgroup %(hostgroup_name)s") % {'hostgroup_name': service.hostgroup_name})
    host_name = service.host_name or ''
    if ',' in host_name:
        c['errors'].append(_("This Service is applied to multiple hosts"))
    return render_to_response('edit_service.html', c, context_instance=RequestContext(request))