首页 文章

获取Nagios中外部网页的主机可用性

提问于
浏览
0

是否有任何可能的方法从Nagios监视工具(已配置主机/主机组)获取主机/主机组的实时可用性,可以将其重定向/捕获到外部网页 . 是否有任何暴露的API来做到这一点,找不到办法 . Nagios在Linux主机上 . 任何帮助或信息表示赞赏 .

EDIT1:

我有一个主机组说例如在这个主机组中的'All_prod'我将为所有主机提供大约20个Linux主机,将会定义一些指标/检查(示例可用性,CPU负载,可用内存..等) . 在这里,我想要仅报告所有主机的可用性指标(例如:如果可用性在24小时内下降,如果可用性下降10分钟,那么它应该为我提供报告,因为它在24小时内停止了10分钟或者只是给我任何相关信息,我可以使用数据评估评估) . 如果有任何API来获取该信息会很好,这会将数据作为json / xml返回 .

1 回答

  • 1

    您可以使用Nagios JSON API . 您可以在此处使用查询构建器http://NAGIOSURL/jsonquery.html .

    但是,要回答您的具体问题,主机的查询将如下所示:

    http://NAGIOSURL/cgi-bin/statusjson.cgi?query=host&hostname=localhost

    这将输出类似于以下内容:

    {
        "format_version": 0,
        "result": {
            "query_time": 1497384499000,
            "cgi": "statusjson.cgi",
            "user": "nagiosadmin",
            "query": "host",
            "query_status": "released",
            "program_start": 1497368240000,
            "last_data_update": 1497384489000,
            "type_code": 0,
            "type_text": "Success",
            "message": ""
        },
        "data": {
            "host": {
                "name": "localhost",
                "plugin_output": "egsdda",
                "long_plugin_output": "",
                "perf_data": "",
                "status": 8,
                "last_update": 1497384489000,
                "has_been_checked": true,
                "should_be_scheduled": false,
                "current_attempt": 10,
                "max_attempts": 10,
                "last_check": 1496158536000,
                "next_check": 0,
                "check_options": 0,
                "check_type": 1,
                "last_state_change": 1496158536000,
                "last_hard_state_change": 1496158536000,
                "last_hard_state": 1,
                "last_time_up": 1496158009000,
                "last_time_down": 1496158536000,
                "last_time_unreachable": 1480459504000,
                "state_type": 1,
                "last_notification": 1496158536000,
                "next_notification": 1496165736000,
                "no_more_notifications": false,
                "notifications_enabled": true,
                "problem_has_been_acknowledged": false,
                "acknowledgement_type": 0,
                "current_notification_number": 2,
                "accept_passive_checks": true,
                "event_handler_enabled": true,
                "checks_enabled": false,
                "flap_detection_enabled": true,
                "is_flapping": false,
                "percent_state_change": 0,
                "latency": 0.49,
                "execution_time": 0,
                "scheduled_downtime_depth": 0,
                "process_performance_data": true,
                "obsess": true
            }
        }
    }
    

    对于主机组:

    http://NAGIOSURL/nagios/cgi-bin/statusjson.cgi?query=hostlist&hostgroup=linux-servers

    这将输出类似于以下内容:

    {
      "format_version": 0,
      "result": {
        "query_time": 1497384613000,
        "cgi": "statusjson.cgi",
        "user": "nagiosadmin",
        "query": "hostlist",
        "query_status": "released",
        "program_start": 1497368240000,
        "last_data_update": 1497384609000,
        "type_code": 0,
        "type_text": "Success",
        "message": ""
      },
      "data": {
        "selectors": {
          "hostgroup": "linux-servers"
        },
        "hostlist": {
          "localhost": 8
        }
      }
    }
    

    希望这可以帮助!

    编辑1(与问题的编辑1对应):

    你默认内置了什么?你可以使用上面的方法来获取每个主机的数据(但听起来你想要每个服务),所以 again 我们将使用在http://YOURNAGIOSURL/jsonquery.html找到的JSON API来获取服务数据 .

    http://YOURNAGIOSURL/nagios/cgi-bin/statusjson.cgi?query=service&hostname=localhost&servicedescription=Current+Load

    我们将得到以下输出(类似的,无论如何):

    {
        "format_version": 0,
        "result": {
            "query_time": 1497875258000,
            "cgi": "statusjson.cgi",
            "user": "nagiosadmin",
            "query": "service",
            "query_status": "released",
            "program_start": 1497800686000,
            "last_data_update": 1497875255000,
            "type_code": 0,
            "type_text": "Success",
            "message": ""
        },
        "data": {
            "service": {
                "host_name": "localhost",
                "description": "Current Load",
                "plugin_output": "OK - load average: 0.00, 0.00, 0.00",
                "long_plugin_output": "",
                "perf_data": "load1=0.000;5.000;10.000;0; load5=0.000;4.000;6.000;0; load15=0.000;3.000;4.000;0;",
                "max_attempts": 4,
                "current_attempt": 1,
                "status": 2,
                "last_update": 1497875255000,
                "has_been_checked": true,
                "should_be_scheduled": true,
                "last_check": 1497875014000,
                "check_options": 0,
                "check_type": 0,
                "checks_enabled": true,
                "last_state_change": 1497019191000,
                "last_hard_state_change": 1497019191000,
                "last_hard_state": 0,
                "last_time_ok": 1497875014000,
                "last_time_warning": 1497019191000,
                "last_time_unknown": 0,
                "last_time_critical": 1497018891000,
                "state_type": 1,
                "last_notification": 0,
                "next_notification": 0,
                "next_check": 1497875314000,
                "no_more_notifications": false,
                "notifications_enabled": true,
                "problem_has_been_acknowledged": false,
                "acknowledgement_type": 0,
                "current_notification_number": 0,
                "accept_passive_checks": true,
                "event_handler_enabled": true,
                "flap_detection_enabled": true,
                "is_flapping": false,
                "percent_state_change": 0,
                "latency": 0,
                "execution_time": 0,
                "scheduled_downtime_depth": 0,
                "process_performance_data": true,
                "obsess": true
            }
        }
    }
    

    对于你想要做的事情(据我所知),最重要的一行是perfdata线:

    "perf_data": "load1=0.000;5.000;10.000;0; load5=0.000;4.000;6.000;0; load15=0.000;3.000;4.000;0;",
    

    这是您用于生成您尝试生成的任何自定义指标报告的数据 .

    请记住,这是Nagios XI中内置的一种内容(不是像您要求的那样是可导出的格式),但是度量组件确实允许您轻松深入查看某些特定于度量的数据 .

    希望 this 有帮助!

相关问题