Tuesday 11 June 2013

Icinga with PNP4Nagios


PNP4Nagios

PNP는 여러 Plugin으로 부터 얻어온 성능 데이터를 분석하여 RRD 데이터베이스 (Round Robin Databases, see RRD Tool)에 자동 저장해주는 Nagios add-on 프로그램이다.
이 페이지에서 PNP4Nagios는 Bulk mode with NPCD 모드로 설정하도록 한다. 자세한 모드 설명은 링크를 참조한다.

Prerequisites

yum install rrdtool-perl rrdtool rrdtool-devel -y
yum install perl-Time-HiRes -y

Build

tar zxvf pnp4nagios-0.6.21 -C /tmp
cd /tmp/pnp4nagios-0.6.21
./configure --with-nagios-user=icinga --with-nagios-group=icinga
make all
make install
make install-webconf
make install-config

Enable BULK Mode with NPCD

make install-init
Start Apache Web Server
service httpd restart
Configuration - Bulk Mode with NPCD
Edit Configuration
/usr/local/pnp4nagios/etc/config.php
$conf['nagios_base'] = "/icinga/cgi-bin";
/usr/local/icinga/etc/icinga.cfg
...생략...
process_performance_data=1
...생략...
#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file

#
# host performance data starting with Nagios 3.0
# 
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
/usr/local/icinga/etc/objects/commands.cfg
# PNP4Nagios
define command{
        command_name    process-service-perfdata-file
        command_line    /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}

define command{
        command_name    process-host-perfdata-file
        command_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}
commands.cfg는 icinga.cfg 파일의 cfg_file 설정에 적용되어있다 가정함
/etc/httpd/conf.d/pnp4nagios.conf
AuthUserFile /usr/local/icinga/etc/htpasswd.users

Start Daemon

chkconfig npcd on
service npcd start
service icinga reload

Check Webpage

http://<IP>/pnp4nagios/

Remove Install file

rm /usr/local/pnp4nagios/share/install.php
Graph
http://<IP>/pnp4nagios/

Integration into Classic-UI

Copy SSI Header File

cp /tmp/pnp4nagios-0.6.18/contrib/ssi/status-header.ssi /usr/local/icinga/share/ssi/status-header.ssi
chown icinga: /usr/local/icinga/share/ssi/status-header.ssi

Default Popups

action_url templates
  • 기존 Template 선언에 action_url을 추가
define host {
  use   linux-server
        name       pnp-host
        register    0
        action_url  /pnp4nagios/graph?host=$HOSTNAME$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_
}

define service {
  use   generic-service
        name        pnp-service
        register    0
        action_url  /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
}
  • 실제로 사용하기 위해서는 pnp-host, pnp-service 템플릿에 다른 템플릿 처럼 여러 설정을 해주어야 Host나 Service Define항목에서 사용하기 좋을 것이다. 위와 같이 use를 사용하여 확장하는 것도 좋은 방법이 될 수 있다.
  • use pnp-host와 pnp-service를 사용하여 PNP4Nagios 사용을 명시
define host{
        name                            generic-host
        use                             pnp-host
...

define service{
        name                            generic-service
        use                             pnp-service
...

Integration into Icinga-Web

Copy Templates Extensions

cp /tmp/icinga-web-1.8.4/contrib/PNP_Integration/templateExtensions/* /usr/local/icinga-web/app/modules/Cronks/data/xml/extensions/

Create and Setting a new Grid View

cp /usr/local/icinga-web/app/modules/Cronks/data/xml/grid/icinga-host-template.xml \
    /usr/local/icinga-web/app/modules/Cronks/data/xml/grid/icinga-my-host-template.xml
cp /usr/local/icinga-web/app/modules/Cronks/data/xml/grid/icinga-service-template.xml \
    /usr/local/icinga-web/app/modules/Cronks/data/xml/grid/icinga-my-service-template.xml
Adding a new field definition
/usr/local/icinga-web/app/modules/Cronks/data/xml/grid/icinga-my-host-template.xml
...생략...
         <field name="pnp4nagios_host_link">
            <!-- datasource maps a data field from api call -->
            <datasource>
                <parameter name="field">HOST_NAME</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Perfdata</parameter>
                <parameter name="width">55</parameter>

                <parameter name="Ext.grid.Column">
                    <parameter name="menuDisabled">true</parameter>
                    <parameter name="fixed">true</parameter>
                </parameter>

                <parameter name="jsFunc">
                    <!-- function to display column with icon in host status grid view -->
                    <parameter>
                        <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                        <parameter name="function">columnImage</parameter>
                        <parameter name="type">renderer</parameter>

                        <parameter name="arguments">
                            <parameter name="image">images/icons/application_view_gallery.png</parameter>
                            <parameter name="css">x-icinga-grid-link</parameter>
                            <parameter name="attr">
                                <parameter name="qtip">Show host perfdata for this host</parameter>
                            </parameter>
                        </parameter>
                    </parameter>

                    <!-- create cell click event for the previously defined column -->
                    <parameter>
                        <parameter name="namespace">Cronk.grid.IcingaColumnRenderer</parameter>
                        <parameter name="function">iFrameCronk</parameter>
                        <parameter name="type">cellclick</parameter>
                        <parameter name="arguments">
                            <parameter name="title">Host perfdata for {host_name}</parameter>
                            <parameter name="url"><![CDATA[/pnp4nagios/index.php/graph?host={host_name}&srv=_HOST_]]></parameter>
                            <parameter name="activateOnClick">true</parameter>
                        </parameter>
                    </parameter>
                </parameter>
            </display>

            <filter>
               <parameter name="enabled">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
            </order>
        </field>
 
    </fields>
</template>
/usr/local/icinga-web/app/modules/Cronks/data/xml/grid/icinga-my-service-template.xml
...생략...
        <field name="pnp4nagios_service_link">
            <!-- datasource maps a data field from api call -->
            <datasource>
                <parameter name="field">SERVICE_NAME</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Perfdata</parameter>
                <parameter name="width">55</parameter>

                <parameter name="Ext.grid.Column">
                    <parameter name="menuDisabled">true</parameter>
                    <parameter name="fixed">true</parameter>
                </parameter>

                <parameter name="jsFunc">
                    <!-- function to display column with icon in host status grid view -->
                    <parameter>
                        <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                        <parameter name="function">columnImage</parameter>
                        <parameter name="type">renderer</parameter>

                        <parameter name="arguments">
                            <parameter name="image">images/icons/application_view_gallery.png</parameter>
                            <parameter name="css">x-icinga-grid-link</parameter>
                            <parameter name="attr">
                                <parameter name="qtip">Show perfdata for this service</parameter>
                            </parameter>
                        </parameter>
                    </parameter>

                    <!-- create cell click event for the previously defined column -->
                    <parameter>
                        <parameter name="namespace">Cronk.grid.IcingaColumnRenderer</parameter>
                        <parameter name="function">iFrameCronk</parameter>
                        <parameter name="type">cellclick</parameter>
                        <parameter name="arguments">
                            <parameter name="title">Service perfdata for {service_name} on {host_name}</parameter>
                            <parameter name="url"><![CDATA[/pnp4nagios/index.php/graph?host={host_name}&srv={service_name}]]></parameter>
                            <parameter name="activateOnClick">true</parameter>
                        </parameter>
                    </parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
            </order>
        </field>
 
    </fields>
</template>
Adding the new grid views to the "Data" Cronk-Container
/usr/local/icinga-web/app/modules/Cronks/config/cronks.xml
...생략...
 <cronks> 
  <cronk name="gridMyHostView">
      <ae:parameter name="module">Cronks</ae:parameter>
      <ae:parameter name="action">System.ViewProc</ae:parameter>
      <ae:parameter name="hide">false</ae:parameter>
      <ae:parameter name="description">Viewing Host status in a grid including perfdata link</ae:parameter>
      <ae:parameter name="name">MyHostStatus</ae:parameter>
      <ae:parameter name="image">cronks.Stats</ae:parameter>
      <ae:parameter name="categories">data</ae:parameter>
      <ae:parameter name="ae:parameter">
          <ae:parameter name="template">icinga-my-host-template</ae:parameter>
      </ae:parameter>
  </cronk>
  <cronk name="gridMyServiceView">
      <ae:parameter name="module">Cronks</ae:parameter>
      <ae:parameter name="action">System.ViewProc</ae:parameter>
      <ae:parameter name="hide">false</ae:parameter>
      <ae:parameter name="description">Viewing service status in a grid including perfdata link</ae:parameter>
      <ae:parameter name="name">MyServiceStatus</ae:parameter>
      <ae:parameter name="image">cronks.Stats2</ae:parameter>
      <ae:parameter name="categories">data</ae:parameter>
      <ae:parameter name="ae:parameter">
          <ae:parameter name="template">icinga-my-service-template</ae:parameter>
      </ae:parameter>
  </cronk>
 </cronks>
    </ae:configuration>
</ae:configurations>

Making the grid view just created as default (Optional)

mv data/xml/grid/icinga-host-template.xml data/xml/grid/icinga-host-template.bak
mv data/xml/grid/icinga-my-host-template.xml data/xml/grid/icinga-host-template.xml
mv data/xml/grid/icinga-service-template.xml data/xml/grid/icinga-service-template.bak
mv data/xml/grid/icinga-my-service-template.xml data/xml/grid/icinga-service-template.xml
이 경우는 /usr/local/icinga-web/app/modules/Cronks/config/cronks.xml에 cronk를 추가할 필요가 없음!

Clear cache

/usr/local/icinga-web/bin/clearcache.sh
or
rm -f /usr/local/icinga-web/app/cache/config/*.php

Check new grid view













Grid view just created


No comments:

Post a Comment