使用Nagios监视非默认端口上的ssh

我只是在Gentoo服务器上部署了Nagios,除了ssh,一切都很好,因为它拒绝连接,所以它标记为“CRITICAL”。 但是,这是因为它运行在与默认值22不同的端口上。如何更改它以便监视正确的端口?

host:~$ /usr/lib/nagios/plugins/check_ssh --help check_ssh v1991 (nagios-plugins 1.4.12) Copyright (c) 1999 Remi Paulmier <[email protected]> Copyright (c) 2000-2007 Nagios Plugin Development Team <[email protected]> Try to connect to an SSH server at specified server and port Usage:check_ssh [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host> 

这回答了你的问题了吗? -p参数让你指定端口,在/etc/nagios/nrpe.cfg中定制检查并放在那里:

 command[check_remote_ssh]= /usr/lib/nagios/plugins/check_ssh -p 1234 some.host 

在ssh pluging config /etc/nagios-plugins/config/ssh.cfg中,有一个名为check_ssh_port的别名。 如果不存在,你可以像上面那样定义它:

 $ cat >> /etc/nagios-plugins/config/ssh.cfg define command{ command_name check_ssh_port command_line /usr/lib/nagios/plugins/check_ssh -p '$ARG1$' '$HOSTADDRESS$' } 

在服务文件/etc/nagios3/conf.d/services_nagios2.cfg中,定义你的ssh服务如下监视:

 define service { hostgroup_name ssh2-servers service_description SSH2 check_command check_ssh_port!12000!server use generic-service notification_interval 240 ; set > 0 if you want to be renotified } 

你的目标取代你的默认SSH端口和服务器12000。

由于上述解决scheme都不适合我,我会发布这个小的变化。

这个定义是默认的(例如: localhost.cfg ),只有-p选项和两者之间的空格。

我想这是两个解决scheme的混合版本。

它在Nagios Core 4上使用nagios-plugins 2.1.1

 define service{ use local-service ; Name of service template to use host_name localhost service_description SSH check_command check_ssh!-p 12345 notifications_enabled 1 } 

您还可以通过以下方式在host_name参数中定义第二个参数“server”:

  define host{ use generic-host ; Name of host template to use host_name host alias host address 92.193.170.124 } # Define a service to check if ssh services are running define service { use generic-service ; Name of service template to use host_name host service_description SSH Port 4959 check_command check_ssh_port!4959 notification_interval 0 ; set > 0 if you want to be renotified } 

因此,如果主机的地址发生变化,则只需修改此参数一次,即可为该主机定义的所有服务。