User Tools

Site Tools


strutture:lnf:dr:calcolo:sistemi:check_mk_custom_check_script

check_mk custom agent check

script sul nodo da monitorare

Sul nodo da monitorare, dopo aver installato e configurato check_mk_agent, creiamo un script bash in /usr/share/check-mk-agent/plugins/.

Es. script che restituisce in output informazioni sullo stato del cluster percona.

vi /usr/share/check-mk-agent/plugins/mk_percona
#!/bin/bash

# Check percona cluster status

if which mysqladmin >/dev/null
then

  mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg -sN \
     -e "select '<<<percona_status>>>' ;
         show global status like 'wsrep_%';"

fi

Diamo i permessi di esecuzione al file

# chmod +x /usr/share/check-mk-agent/plugins/mk_percona

script sul nodo check_mk server

Sul nodo check_mk server verifichiamo che l'agent risponda e restituisca i valori attesi generati dallo script mk_percona appena creato:

# su - lnf

# check_mk -d [PERCONA_HOST] | fgrep -A 5 percona_status

Se l'agent è configurato correttamente l'output sarà:

<<<percona_status>>>
wsrep_local_state_uuid	de5a461b-7059-11e7-9135-b6f59edaa63d
wsrep_protocol_version	7
wsrep_last_committed	28327916
wsrep_replicated	4751904
wsrep_replicated_bytes	19439632755

Creiamo adesso uno script Python per analizzare l'output ricevuto dell'agent. Lo script dovrà essere salvato in /omd/sites/lnf/share/check_mk/checks/.

Il file DEVE avere lo stesso nome definito nello script sull'agent (nell'esempio percona_status).

# vi /omd/sites/lnf/share/check_mk/checks/percona_status
#!/usr/bin/env python

def parse_mysql(info):
    values = {}
    for line in info:
        if len(line) == 2:
            varname, value = line
            try:
                value = int(value)
            except:
                pass
        else:
            varname = line[0]
            value = None

        values[varname] = value
    return values


def inventory_percona_status(info):
    values = parse_mysql(info)
    if 'wsrep_local_state_comment' in values and 'wsrep_cluster_size' in values:
        return [(None, {})]

def check_percona_status(item, params, info):
    values = parse_mysql(info)
    if 'wsrep_local_state_comment' not in values:
        return (3, 'Percona sync information are missing')

    if 'wsrep_cluster_size' not in values:
        return (3, 'Percona cluster size information are missing')

     # Clustr sync status
    cluster_sync_status = values['wsrep_local_state_comment']

    if cluster_sync_status == "Synced":
        syncStatus = 0
        syncStatus_txt = "Cluster is synced. "
    else:
        syncStatus = 2
        syncStatus_txt = "Cluster isn't synced. "

    # Clustr size
    cluster_size = float(values['wsrep_cluster_size'])

    if cluster_size > 1:
        sizeStatus = 0
    elif cluster_size == 1:
        sizeStatus = 2

    sizeStatus_txt = "Number of instances"

    if syncStatus == 0 and sizeStatus == 0:
        status = 0
    else:
        status = 2

    status_txt = syncStatus_txt + sizeStatus_txt

    return (status, status_txt + ': %d' % (cluster_size))


check_info['percona_status'] = {
    "check_function"          : check_percona_status,
    "inventory_function"      : inventory_percona_status,
    "service_description"     : "Percona Cluster status",
    "has_perfdata"            : False,
}
strutture/lnf/dr/calcolo/sistemi/check_mk_custom_check_script.txt · Last modified: 2018/02/01 18:09 by tota@infn.it

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki