将 nagios 插件添加到 nconf 模式

将 nagios 插件添加到 nconf 模式

我已经安装了 nagios 和 nconf,并开始添加主机和服务定义。但我注意到,可用于添加服务的 nagios 模块列表与我的 nagios 服务器上可用的模块列表之间存在很大差异。

要查看 nconf 允许您配置哪些 nagios 插件:

SELECT CV.attr_value AS nagios_plugin
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
JOIN ConfigValues CV ON CV.fk_id_attr = CA.id_attr
WHERE
CC.config_class = 'checkcommand' AND
CA.attr_name = 'command_name';

返回

+----------------------+
| nagios_plugin        |
+----------------------+
| check_local_disk     |
| check_local_load     |
| check_local_procs    |
| check_local_users    |
| check_local_swap     |
| check_local_mrtgtraf |
| check_ftp            |
| check_hpjd           |
| check_snmp           |
| check_http           |
| check_ssh            |
| check_dhcp           |
| check_ping           |
| check_pop            |
| check_imap           |
| check_smtp           |
| check_tcp            |
| check_udp            |
| check_nt             |
+----------------------+

与磁盘上的内容相比ls -1 /usr/lib/nagios/plugins,显示有近 70 个 nagios 插件未在 nconf 中公开!

我的问题是 - 在我设计 SQL 语句来添加对我感兴趣的命令的支持之前,例如check_mysql,是否有一个地方INSERT已经提供了适当的语句?有没有更好的方法可以解决这个问题?似乎 nconf 只为您提供了一组有限的 nagios 插件供您开箱即用。

答案1

我最终尝试用自己的能力来添加对 的支持check_mysql。由于我想要连接的服务器支持 SSL,我在 nconf 中构建了一个特定于 ssl 连接的检查命令,名为check_mysql_ssl。这是我运行以添加它的 SQL。我将在不久的将来撰写一篇完整的博客文章,其中包含更多详细信息。注意,SQL 数量庞大的原因是 nconf 数据库使用的 EAV 范例 ;)

-- ------------------------------------------------------------
-- Store some variables for future use
-- ------------------------------------------------------------
SELECT @command_name_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'command_name';

SELECT @command_line_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'command_line';

SELECT @command_syntax_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'command_syntax';

SELECT @default_params_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'default_params';

SELECT @command_param_count_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'command_param_count';

SELECT @default_service_name_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'default_service_name';

SELECT @service_template_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'service_template';

SELECT @default_service_dependency_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'default_service_dependency';

SELECT @dependency_execution_failure_criteria_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'dependency_execution_failure_criteria';

SELECT @dependency_notification_failure_criteria_attr_id := CA.id_attr, @config_class_id := CC.id_class
FROM ConfigClasses CC
JOIN ConfigAttrs CA ON CA.fk_id_class = CC.id_class
WHERE
  CC.config_class = 'checkcommand' AND
  CA.attr_name = 'dependency_notification_failure_criteria';

-- ------------------------------------------------------------
-- Create a new ConfigItem
-- ------------------------------------------------------------
INSERT INTO ConfigItems SET fk_id_class = @config_class_id;
SET @config_item_id := LAST_INSERT_ID();


-- ------------------------------------------------------------
-- Add support for check_mysql
-- ------------------------------------------------------------

-- command name
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('check_mysql_ssl', @command_name_attr_id, @config_item_id);

-- command line
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('$USER1$/check_mysql -H $ARG1$ -u $ARG2$ -p $ARG3$ -l -C $ARG4$ -a $ARG5$ -k $ARG6$', @command_line_attr_id, @config_item_id);

-- command syntax
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('ARG1=host, ARG2=username, ARG3=password, ARG4=ca-cert, ARG5=client-cert, ARG6=client-key', @command_syntax_attr_id, @config_item_id);

-- default params
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('!', @default_params_attr_id, @config_item_id);

-- command param count
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('6', @command_param_count_attr_id, @config_item_id);

-- default service name
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('', @default_service_name_attr_id, @config_item_id);

-- service template
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('', @service_template_attr_id, @config_item_id);

-- default service dependency
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('', @default_service_dependency_attr_id, @config_item_id);

-- depdency execution failure critieria
-- @note Return non-zero - how to specify that ??
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('', @dependency_execution_failure_criteria_attr_id, @config_item_id);

-- depdency notification failure critieria
-- @note Return non-zero - how to specify that ??
INSERT INTO ConfigValues (attr_value, fk_id_attr, fk_id_item)
VALUES ('', @dependency_notification_failure_criteria_attr_id, @config_item_id);

相关内容