Objetivo
Demonstrar como efetuar a integração do sistema de alertas Pagerduty com o OpMon.
Público-alvo
Administradores de OpMon que desejam a integração para o recebimento de alertas através da plataforma Pagerduty.
Pré-requisitos
- Possuir acesso de administrador na plataforma Pagerduty.
- O servidor deve possuir o Python na versão 2.7 ou superior
Configurando o token de integração
Acesse o site do Pagerduty e faça login com a sua conta de administrador. Para criarmos um token de integração clique em “Configuration” e logo após no submódulo “Services”.
Na página seguinte clique em “Add Services”.
No campo “Integration Type” marque a opção “Nagios”. Não esqueça de adicionar um nome e uma descrição para esta integração, por fim clique em “Add service” no final da página.
Na próxima tela será apresentando o token de integração, guarde esta chave, pois brevemente o utilizaremos na configuração dos comandos de notificações.
Instalando o agente no OpMon (versão 9.x e versão 10.x)
Para que possamos efetuar a instalação do agente no OpMon, você precisa de acesso root na console e possuir a versão 2.7 ou superior do Python instalada.
[root@opmon ~]#sh -c 'cat >/etc/yum.repos.d/pdagent.repo <<EOF
[pdagent]
name=PDAgent
baseurl=https://packages.pagerduty.com/pdagent/rpm
enabled=1
gpgcheck=1
gpgkey=https://packages.pagerduty.com/GPG-KEY-RPM-pagerduty
EOF'
[root@opmon ~]# yum install pdagent pdagent-integrations -y
Iniciando o serviço do Pagerduty
(OpMon versão 9.x)
[root@opmon ~]# /etc/init.d/pdagent status pdagent (pid 25190) is running.
IMPORTANTE!
Caso ocorra o seguinte erro ao iniciar o serviço pdagent no OpMon, semelhante ao erro abaixo:
[root@opmon ~]# /etc/init.d/pdagent start Starting: pdagentTraceback (most recent call last): File "/usr/share/pdagent/bin/pdagentd.py", line 75, in <module> import pdagent.config ImportError: No module named 'pdagent' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/pdagent/bin/pdagentd.py", line 81, in <module> import pdagent.config ImportError: No module named 'pdagent' [root@opmondemo ~]#
Realize o seguinte procedimento:
[root@opmon ~]# cp -a /usr/lib/python2.7/site-packages/pdagent /usr/share/pdagent/bin/
E após inicie o serviço com o seguinte comando:
[root@opmon~]# /etc/init.d/pdagent restart Stopping: pdagent. Starting: pdagent.
Iniciando o serviço do Pagerduty
(OpMon versão 10.x)
IMPORTANTE!
Na versão 10.x do OpMon, o serviço do Pagerduty deve ser copiado para o Systemd do sistema (CentOS 8, Oracle Linux 8 ou Red Hat 8), para ser iniciado:
[root@opmon~]# cp /var/lib/pdagent/scripts/pdagent.service /etc/systemd/system/pdagent.service [root@opmon~]# systemctl daemon-reload [root@opmon~]# systemctl start pdagent.service [root@opmon~]# sudo systemctl status pdagent
TESTES E TROUBLESHOOTINGS!
Caso ainda o pdagent não esteja rodando, precisamos validar a versão instalada do Python. Para isso, digite o comando abaixo:
[root@opmon ~]# python -V
[root@opmon ~]# find / -name pytho* /lib/python /var/local/opmon/share/oplib/libjs/editarea/edit_area/reg_syntax/python.js /usr/lib64/python2.6 /usr/lib64/python2.6/idlelib/Icons/python.gif /usr/lib64/python3.4 /usr/lib64/python3.4/idlelib/Icons/python.gif /usr/include/python3.4m /usr/include/python2.6 /usr/lib/python2.6 /usr/lib/python3.6 /usr/lib/python2.7 /usr/lib/python3.7 /usr/lib/python3.4 /usr/bin/python3.4m /usr/bin/python2.6 /usr/bin/python /usr/bin/python2 /usr/bin/python3 /usr/bin/python3.4 /usr/share/man/man1/python.1.gz /usr/share/man/man1/python3.4.1.gz /usr/share/man/man1/python3.1.gz /usr/share/doc/python-pymongo-2.5.2 /usr/share/doc/python-pymongo-2.5.2/doc/python3.rst /usr/share/doc/gamin-0.1.10/python.html /usr/share/doc/python-libs-2.6.6 /usr/share/doc/python-urlgrabber-3.9.1 /usr/share/doc/python-2.6.6 /usr/share/doc/libxslt-1.1.26/python.html /usr/share/doc/python-iniparse-0.3.1 /usr/share/doc/python34-3.4.5 /usr/share/doc/python-backports-ssl_match_hostname-3.4.0.2 /usr/share/doc/python-bson-2.5.2 /usr/share/doc/python-bson-2.5.2/doc/python3.rst /usr/share/doc/python-pycurl-7.19.0 /usr/share/doc/python34-libs-3.4.5
cp -a /usr/lib/VERSÃO DO PYTHON ESCOLHIDA/site-packages/pdagent /usr/share/pdagent/bin/
Editar o arquivo pdagentd.py
vi /usr/share/pdagent/bin/pdagentd.py
Na primeira linha apontar a versão do python escolhida para executar o script ou apontar o diretório onde o mesmo está instalado. Salvar o arquivo e executá-lo
#!/usr/bin/python3.4 # # PagerDuty Agent daemon. # See https://github.com/PagerDuty/agent for details. # # Copyright (c) 2013-2014, PagerDuty, Inc. <info@pagerduty.com> # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the copyright holder nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # standard python modules import logging.handlers import os "/usr/share/pdagent/bin/pdagentd.py" 415L, 13164C
Valide se o serviço está rodando:
[root@opmon~]# ps -ef | grep pdagent pdagent 24384 1 0 20:06 ? 00:00:00 /usr/bin//python3.4 /usr/share/pdagent/bin/pdagentd.py root 24777 25824 0 20:06 pts/0 00:00:00 grep pdagent
Documentação Oficial do Pagerduty, caso necessário:
https://www.pagerduty.com/docs/guides/agent-install-guide/
https://support.pagerduty.com/docs/pagerduty-agent-troubleshooting-guide
DICA!
O log do serviço fica em /var/log/pdagent/pdagentd.log, para acompanhamento, caso necessário.
Criando o comando de notificação no OpMon
Clique no módulo “Ferramentas“, logo após no submódulo “Configurações“, na área de atalhos (localizada no lado esquerdo da tela) clique em “Commands” e em seguida, clique em “Add A New Command“, veja:
Insira um nome para o comando de notificação e uma descrição, conforme abaixo:
Agora precisamos incluir em “Command Line” os parâmetros do plugin adjunto do token de integração. Serão criados dois comandos de notificações, um para host e outro para serviços.
Host
/usr/share/pdagent-integrations/bin/pd-nagios -n host -k my_token -t "$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f HOSTSTATE="$HOSTSTATE$" -f HOSTDISPLAYNAME="$HOSTDISPLAYNAME$" -f HOSTPROBLEMID="$HOSTPROBLEMID$"
Serviço
/usr/share/pdagent-integrations/bin/pd-nagios -n service -k my_token -t "$NOTIFICATIONTYPE$" -f SERVICEDESC="$SERVICEDESC$" -f SERVICESTATE="$SERVICESTATE$" -f HOSTNAME="$HOSTNAME$" -f HOSTDISPLAYNAME="$HOSTDISPLAYNAME$" -f SERVICEDISPLAYNAME="$SERVICEDISPLAYNAME$" -f SERVICEPROBLEMID="$SERVICEPROBLEMID$" -f SERVICEOUTPUT="$SERVICEOUTPUT$"
Após a configuração em “Command Line” clique em “Create Command”, conforme abaixo:
Atenção: reproduza o mesmo processo com a finalidade de criar o comando de notificações para serviços.
Configurando o perfil do usuário
Clique no módulo “Ferramentas“, logo após no submódulo “Configurações“, na área de atalhos (localizada no lado esquerdo da tela) clique em “Contacts” e em seguida, clique no usuário para configurar os comandos de notificações, veja:
Em “Add New Host Notification Command” selecione o comando “notify-host-by-pagerduty” e depois clique em “Add Command”.
Em “Service Notification Command” selecione o comando “notify-service-by-pagerduty” e depois clique em “Add Command”.
Para que as configurações sejam aplicadas de forma efetiva, aplique um export full no OpMon, feito isso a integração entre OpMon e Pagerduty está pronta.