Monitoramento do PfSense com Check_MK

olho-humano

Para o monitoramento de infraestrutura de rede de ensino, usamos o Check_MK . O Check_MK suporta uma variedade de serviços e agentes. Os dados podem ser monitorados com o agente Check_MK, SNMP ou simplesmente por ping. Costumávamos monitorar o firewall através do SNMP, que já está integrado ao pfSense (você pode ativar o SNMP através dos Serviços → SNMP ). Isso já cobre a maioria dos serviços, como todas as interfaces de rede. Faltam informações importantes. Isso inclui a carga real da CPU ou dos discos rígidos. Para obter essas informações, precisa instalar o agente Check_MK no firewall.

Instalando o agente Check_Mk no pfSense

Mostrarei a instalação através de uma conexão SSH com o firewall. Como alternativa, você também pode inserir todos os comandos em Diagnóstico → Prompt de Comando .

O Check_MK-Agent é um script bash. Portanto, o bash deve ser instalado primeiro:

 $ pkg install -y bash

Em seguida, criamos dois diretórios:

$ mkdir -p /opt/bin
$ mkdir -p /opt/etc/xinetd.d

Em seguida, devemos baixar o Check_MK-Agent em nosso diretório recém-criado e torná-lo executável:

$ curl --output /opt/bin/check_mk_agent 'https://git.mathias-kettner.de/git/?p=check_mk.git;a=blob_plain;f=agents/check_mk_agent.freebsd;hb=HEAD'
$ chmod +x /opt/bin/check_mk_agent

Os dados do agente Check_MK são recuperados através do telnet. Portanto, precisamos de um arquivo de configuração. Para fazer isso, copie o seguinte conteúdo (de preferência através de Diagnóstico → Editar arquivo ) para o arquivo /opt/etc/xinetd.d/check_mk:

# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   (    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             [email protected] |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.
 
service check_mk
{
    type           = UNLISTED
    port           = 6556
    socket_type    = stream
    protocol       = tcp
    wait           = no
    user           = root
    server         = /opt/bin/check_mk_agent
 
    # If you use fully redundant monitoring and poll the client
    # from more then one monitoring servers in parallel you might
    # want to use the agent cache wrapper:<br />
 
    #server         = /usr/bin/check_mk_caching_agent
 
    # configure the IP address(es) of your Nagios server here:
    #only_from      = 127.0.0.1 10.0.20.1 10.0.20.2
 
    # Don't be too verbose. Don't log every check. This might be
    # commented out for debugging. If this option is commented out
    # the default options will be used for this service.
    log_on_success =
 
    disable        = no
}

Agora temos que definir algumas configurações de filtro. O script a seguir faz as alterações necessárias no arquivo /etc/inc/filter.inc automaticamente. Para fazer isso, crie o arquivo /opt/filter_check_mk_cron (novamente com Diagnóstico → Editar arquivo ).

#!/bin/sh
 
grep includedir /etc/inc/filter.inc
if [ $? -eq 0 ]
then
        exit 0
else
        awk '/fclose\(\$xinetd_fd\)\;/{print "fwrite($xinetd_fd, \"includedir /opt/etc/xinetd.d\");"}1' /etc/inc/filter.inc > /etc/inc/filter.inc.temp
        mv /etc/inc/filter.inc.temp /etc/inc/filter.inc
fi
exit 0

Temos que configurar o bit executável novamente e executá-lo.

$ chmod +x /opt/filter_check_mk_cron
$ ./opt/filter_check_mk_cron

E finalmente recarregue os filtros (via Status → Recarregar filtro ) e agora podemos verificar se o Check_MK Agent funciona (configure o IP do firewall de acordo):

 $ telnet 192.168.1.1 6556

Se tudo estiver configurado corretamente, você verá a saída do agente Check_MK.

Configure o pfSense no servidor Check_MK

Agora temos que adicionar o firewall como host no Check_MK ou editar o host existente no WATO. Além do IP, da comunidade SNMP e do nome do host, selecionamos Dual Check: Check_MK Agent + SNMP como o tipo de agente. Com um clique em Salvar e vá para Serviços , podemos ativar os serviços desejados.

Verifique a configuração

Agora, todas as informações importantes estão sempre disponíveis rapidamente. Aqui está um trecho:

Verificar serviços

Conclusão

O Check_MK é um software de monitoramento muito flexível e excelente. Nós o usamos há algum tempo em uma instituição de ensino e as possibilidades de personalização são quase infinitas em termos de notificações e dispositivos a serem monitorados.

Deixe um comentário