Skip to content

Instantly share code, notes, and snippets.

@gnh1201
Last active April 20, 2020 08:30
Show Gist options
  • Save gnh1201/792964e9719d2f62157cf46e394888f5 to your computer and use it in GitHub Desktop.
Save gnh1201/792964e9719d2f62157cf46e394888f5 to your computer and use it in GitHub Desktop.
자빅스 심각도 그라파나로 보내기 (Send severities from Zabbix to Grafana)

자빅스 심각도 그라파나로 보내기 (Send severities from Zabbix to Grafana)

  1. ReasonableFramework 설치 (v1.6.2)

  2. 자빅스(Zabbix) 접속 정보 설정 (파일: /stroage/config/3rdparty.ini.php)

zabbix_host=[127.0.0.1]
zabbix_username=[username]
zabbix_password=[username]
zabbix_protocol=http
  1. 컨트롤러 작성 (파일: /route/zabbix.status.json.php)
<?php
loadHelper("zabbix.api");

zabbix_authenticate();

$hosts = zabbix_get_hosts();

$data = array();
foreach($hosts as $host) {
    $severity = 0;

    $triggers = zabbix_get_triggers($host->hostid);
    foreach($triggers as $trigger) {
        $_severity = intval($trigger->priority);
        if($_severity > $severity) {
            $severity = $_severity;
        }
    }

    $data[] = array(
        "target" => $host->host,
        "datapoints" => array(
            array($severity, get_current_timestamp())
        )
    );
};

header("Content-Type: application/json");
$result = json_encode($data);

echo $result;
  1. .htaccess 설정 (파일: /.htaccess)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~gw/index.php/$1 [L]
  1. 그라파나(Grafana) 설정

    1. JSON 플러그인 설치 - https://grafana.com/grafana/plugins/simpod-json-datasource
    2. 새로운 Datasource를 JSON으로 선택
    3. Datasource 이름을 지정 - 예시: Zabbix Status API
    4. JSON 주소 입력 - https://localhost/zabbix.status.json (예시)
    5. Test & Save 누름 - 성공 메시지 확인
    6. 저장
  2. 패널(Panel) 설정

    1. Zabbix Status API(예시)를 선택하여 패널을 이용.

문의사항

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment