将iTop与Nagios集成

本页说明如何集成iTop和Nagios。

FIXMESOAP被认为已过时,现在创建工单的首选方式是使用REST/JSON接口.

通过此集成:

  • Nagios警报在iTop中变成事件工单
  • 设备的Nagios状况的详细信息直接在iTop中可见(作为对象上的一个附加选项卡)

尽管Nagios的配置非常具体(命令,处理程序的定义),但相同的原理也可以应用于任何基于Web的,能够在接收到警报后运行命令行脚本的监控工具。

在iTop中将Nagios警报转换为工单的好处很多,例如:

  • 从创建到其解决都可以跟踪工单
  • 可以将SLA分配给工单以确保其解决按时完成
  • 由于其组件之一的失效,iTop可以计算“受影响的”基础结构。 “受影响的”项目会自动添加到事件工单
  • iTop可以通知受到事件影响的各个人

在iTop中自动创建事件工单

本节介绍如何配置Nagios在iTop中自动创建事件工单。由于Nagios的“命令”基于命令行脚本,因此编写了一个特殊的PHP脚本,该脚本包装了iTop的SOAP Web服务,用于从命令行创建事件事件。请注意,由于Nagios调用的命令行脚本使用SOAP web-服务在iTop中创建事件,因此,只要从Nagios工单到iTop的HTTP(S)连接成为可能,就可以将Nagios和iTop安装在不同的工单上。

该脚本称为“ createTicket-nagios.php”。可以从这里下载:http://www.combodo.com/documentation/createTicket-nagios.zip

将此脚本复制到nagios服务器上的目录中(例如etc/nagios3),并在同一目录中复制从iTop实例的目录“ webservices”中获取的文件“ itop soap types.inc.php”。

  • 该脚本使用在Nagios中触发警报的主机的主机名,以识别iTop中受影响的对象。因此,主机名必须是唯一的。
  • 该脚本仅触发处于HARD状态的与Nagios对接警报。此外,它要求在iTop中已经配置了默认的工作组到分派,工单,默认的提交人和默认的客户。 (请参阅此处的iTop文档以获取有关工作组,呼叫者和客户的更多详细信息)
  • 工单的严重性始终相同,默认情况下设置为“严重”。
  • 该脚本只是描述如何使用iTop soap web服务的示例。随时根据您的要求改进依赖。

脚本的开头列出了用于工单创建的所有参数,如下所示,并且必须适应您的配置。

<?php
// Adjust these settings to fit your iTop installation
// iTop Server location
define('ITOP_SERVER_URL', 'https://localhost/webservices/itop.wsdl.php');
// Valid credentials for connecting to iTop
define('ITOP_USERNAME', 'admin');
define('ITOP_PASSWORD', 'admin2');
// Default settings for creating the incident ticket
define('DEFAULT_IMPACT', 2); // 1 = department, 2 = service, 3 = person
define('DEFAULT_URGENCY', 2); // 1 = high, 2 = medium, 3 = low
define('DEFAULT_CALLER_NAME', 'Dali');
define('DEFAULT_ORGANIZATION_NAME', 'Demo');
define('DEFAULT_SERVICE_NAME', 'HW Monitoring');
define('DEFAULT_SERVICE_SUBCATEGORY', 'HW Troubleshooting');
define('DEFAULT_WORKGROUP_NAME', 'Hardware support');
// End of instance-specific parameters

在Nagios服务器上安装文件

  • 步骤1:将此脚本以及itopsoaptypes.class.inc.php复制到<yourDirectory>中
  1. 第2步:通过将以下内容添加到您的Nagios命令文件中来定义新的Nagios Command(大多数情况下,将其称为commands.cfg)

# Create incident tickets in iTop command definition define command{ command_name create-iTop-ticket command_line <php path> <yourDirectory>/createTicket-nagios.php \"$HOSTNAME$\" \"$SERVICEDESC$\" \"$SERVICESTATE$\" \"$SERVICESTATETYPE$\" \"$LONGSERVICEOUTPUT$\" }

其中<php path>是PHP的完整路径,而<your_directory>是您安装iTop脚本的安装路径。

您可以通过手动运行PHP脚本测试工单创建。

步骤3:在事态处理程序选项中,对于应该触发器和工单创建的每个主机或服务模板,使用以下命令:

您可以使用大多数时候在nagios.cfg中定义的以下选项为所有主机和服务全局定义它:

global_host_event_handler=create-iTop-ticket
global_service_event_handler= create-iTop-ticket

或使用以下选项针对每个主机和服务:

event_handler   create-iTop-ticket
event_handler_enabled  1

如果选择后一个选项,则必须为创建的每个主机和服务模板配置处理程序。

一旦完成,下一次您将在Nagios中收到HARD警报时,它将在iTop中自动创建工单!

好酷!

在iTop中查看Nagios状况

当给定的对象的详细信息显示在iTop中时,浏览器框架中会有多个选项卡。您可以创建一个新选项卡,显示选定的对象的Nagios框架。

  • 在类InfrastructureCI中更改XT​​职能DisplayBareRelations
  • 当您不处于编辑模式时,这将为生产中的所有InfrastuctureCI添加一个Tab Nagios。

function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); if (!$bEditMode) { $sStatus = $this->Get('status'); $sName = $this->Get('name'); if ($sStatus == 'production') { $oPage->SetCurrentTab(Dict::S('Nagios')); $oPage->add('<div id="checkmk" style="width:100%;height:500px;">'); $oPage->add('<iframe style="border:0;padding:0;margin:0;width:100%;height:500px;overflow:auto" '); $oPage->add('src="https://<nagios_path>/cgi-bin/status.cgi?host=$sName">'); $oPage->add('</iframe></div>'); } } }

  • 不要忘记将“ <nagios_path>”设置为适合您的安装的URL。

注意,只有在iTop中使用的对象的名称等于Nagios中对象的主机名时,该显示才起作用。

完成后,保存文件并在浏览器中重新加载“详细信息”页面。

结果应类似于下图:

https://www.itophub.io/wiki/media?w=627&tok=80a64d&media=mediawiki%3Anagiosinitop.png

原贴链接:https://www.itophub.io/wiki/page?id=2_7_0%3Aadvancedtopics%3Anagios


Integrating iTop with Nagios

This page explains how to integrate iTop and Nagios.

FIXME SOAP is considered as obsolete, the preferred manner to create tickets is now using the REST/JSON interface.

Through this integration:

  • Nagios alarms are turned into Incident tickets in iTop

  • The details of the Nagios status for a device is visible directly within iTop (as an extra tab on the object)

Though the configuration of Nagios is quite specific (definition of a command, a handler), the same principles can be applied to any web-based monitoring tool that is capable of running a command line script upon reception of an alarm.

The advantage of transforming the Nagios alarm into a ticket in iTop are numerous, for instance:

  • the ticket can be tracked from its creation to its resolution

  • A SLA can be assigned to the ticket to ensure its resolution is done on time

  • iTop can compute the “impacted” infrastructures due to a failure of one of its components. The “impacted” items are automatically added to the Incident ticket

  • iTop can notify the various persons impacted by the incident

Automating the creation of incident tickets in iTop

This section describes how to configure Nagios to create automatically incident tickets in iTop. Since Nagios “commands” are based on command line script, a special PHP script was written that wraps iTop's SOAP web service for creating an incident ticket, from the command line. Note that since the command line script called by Nagios uses a SOAP web-service to create the ticket in iTop, Nagios and iTop can be installed on different server, provided an HTTP(S) connection is possible from the Nagios server to iTop.

This script is called “createTicket-nagios.php”. It can be downloaded from here: http://www.combodo.com/documentation/createTicket-nagios.zip

Copy this script in a directory on the nagios server (for example /etc/nagios3) and copy in the same directory the file 'itopsoaptypes.inc.php' taken from the directory 'webservices' of your iTop instance.

  • This script is using the hostname of the host that triggered the alarm in Nagios in order to identify the impacted object in iTop. Therefore the hostname has to be unique.

  • The script triggers tickets only for Nagios alarms that are in HARD state. Moreover, it requires a default Workgroup to assign the ticket, a default caller and a default customer to be already configured in iTop. (Look at the iTop documentation here to have more details on Workgroups, Callers and Customers)

  • The severity of the ticket is always the same, set to critical by default.

  • This script is just an example describing how to use iTop soap web service. Feel free to improved depending on your requirements.

All parameters used for ticket creation are listed at the beginning of the script, as shown below, and must be adapted to your configuration.

<?php
// Adjust these settings to fit your iTop installation
// iTop Server location
define('ITOP_SERVER_URL', 'https://localhost/webservices/itop.wsdl.php');
// Valid credentials for connecting to iTop
define('ITOP_USERNAME', 'admin');
define('ITOP_PASSWORD', 'admin2');
// Default settings for creating the incident ticket
define('DEFAULT_IMPACT', 2); // 1 = department, 2 = service, 3 = person
define('DEFAULT_URGENCY', 2); // 1 = high, 2 = medium, 3 = low
define('DEFAULT_CALLER_NAME', 'Dali');
define('DEFAULT_ORGANIZATION_NAME', 'Demo');
define('DEFAULT_SERVICE_NAME', 'HW Monitoring');
define('DEFAULT_SERVICE_SUBCATEGORY', 'HW Troubleshooting');
define('DEFAULT_WORKGROUP_NAME', 'Hardware support');
// End of instance-specific parameters

Installing the files on the Nagios server

  • Step 1: Copy this script in <yourDirectory> as well as itopsoaptypes.class.inc.php

  1. Step 2: Define a new Nagios Command by adding following to your Nagios command file (most of the time it is called commands.cfg)

# Create incident tickets in iTop command definition define command{ command_name create-iTop-ticket command_line <php path> <yourDirectory>/createTicket-nagios.php \"$HOSTNAME$\" \"$SERVICEDESC$\" \"$SERVICESTATE$\" \"$SERVICESTATETYPE$\" \"$LONGSERVICEOUTPUT$\" }

where <php path> is the full path for PHP and <your_directory> the path where you installed installed the iTop scripts.

You can test the ticket creation by running manually the PHP script.

Step 3 : Use this command in an event handler option for each host or service template that should trigger a ticket creation:

You can define it globally for all hosts and services using following options defined most of the time in nagios.cfg:

global_host_event_handler=create-iTop-ticket
global_service_event_handler= create-iTop-ticket

Or for each host and services using following options:

event_handler   create-iTop-ticket
event_handler_enabled  1

if you choose the latter option, you will have to configure the handler for each host and service templates you create.

Once done, next time you will have a HARD alarm in Nagios it will create a ticket automatically in iTop !

Cool !

Viewing the Nagios status in iTop

When the details of a given object are displayed in iTop there are several tabs in the browser's frame. You can create a new tab displaying a Nagios frame for the selected object.

  • Alter in the class InfrastructureCI the function DisplayBareRelations

  • This will add a Tab Nagios for all InfrastuctureCI on production, when you are not in edit mode.

function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); if (!$bEditMode) { $sStatus = $this->Get('status'); $sName = $this->Get('name'); if ($sStatus == 'production') { $oPage->SetCurrentTab(Dict::S('Nagios')); $oPage->add('<div id="checkmk" style="width:100%;height:500px;">'); $oPage->add('<iframe style="border:0;padding:0;margin:0;width:100%;height:500px;overflow:auto" '); $oPage->add('src="https://<nagios_path>/cgi-bin/status.cgi?host=$sName">'); $oPage->add('</iframe></div>'); } } }

  • Don't forget to set the “<nagios_path>” to the appropriate URL for your installation.

Note that the display will work only if the name of the object you are using in iTop is equal to the hostname of the object in Nagios.

Once done, save the file and reload the “details” page in your browser.

The result should be similar to following picture:

https://www.itophub.io/wiki/media?w=627&tok=80a64d&media=mediawiki%3Anagiosinitop.png

标签:
由 superadmin 在 2020/08/27, 16:24 创建
    

需要帮助?

如果您需要有关XWiki的帮助,可以联系:

深圳市艾拓先锋企业管理咨询有限公司