User Tools

Site Tools


strutture:lnf:dr:calcolo:sistemi:check_mk_custom_check_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
strutture:lnf:dr:calcolo:sistemi:check_mk_custom_check_script [2018/02/01 15:26]
tota@infn.it
strutture:lnf:dr:calcolo:sistemi:check_mk_custom_check_script [2018/02/01 18:09] (current)
tota@infn.it
Line 1: Line 1:
 +===== 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.
 + 
 +<code>
 +vi /usr/share/check-mk-agent/plugins/mk_percona
 +</code>
 +
 +<code>
 +#!/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
 +</code>
 +
 +Diamo i permessi di esecuzione al file
 +
 +<code>
 +# chmod +x /usr/share/check-mk-agent/plugins/mk_percona
 +</code>
 +
 +==== 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:
 +
 +<code>
 +
 +# su - lnf
 +
 +# check_mk -d [PERCONA_HOST] | fgrep -A 5 percona_status
 +
 +</code>
 +
 +Se l'agent è configurato correttamente l'output sarà:
 +
 +<code>
 +<<<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
 +</code>
 +
 +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'').
 +
 +<code>
 +# vi /omd/sites/lnf/share/check_mk/checks/percona_status
 +</code> 
 +
 +<code>
 +#!/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,
 +}
 +</code>
 +