简体   繁体   English

使用Nagios监控URL

[英]Monitoring URLs with Nagios

I'm trying to monitor actual URLs, and not only hosts, with Nagios, as I operate a shared server with several websites, and I don't think its enough just to monitor the basic HTTP service (I'm including at the very bottom of this question a small explanation of what I'm envisioning). 我正在尝试使用Nagios来监控实际的URL,而不仅仅是主机,因为我在运行带有多个网站的共享服务器时,我认为它不足以监控基本的HTTP服务(我包括在内这个问题的底部是我想象的一个小解释。

(Side note: please note that I have Nagios installed and running inside a chroot on a CentOS system. I built nagios from source, and have used yum to install into this root all dependencies needed, etc...) (旁注:请注意我在CentOS系统上的chroot中安装并运行了Nagios。我从源代码构建了nagios,并使用yum在这个root中安装了所有需要的依赖项等等。)


I first found check_url , but after installing it into /usr/lib/nagios/libexec, I kept getting a "return code of 255 is out of bounds" error. 我首先找到了check_url ,但是在将它安装到/ usr / lib / nagios / libexec后,我不断得到“返回代码255超出界限”错误。 That's when I decided to start writing this question (but wait! There's another plugin I decided to try first!) 就在那时我决定开始写这个问题(但是等等!还有另一个插件,我决定先试试!)

After reviewing This Question that had almost practically the same problem I'm having with check_url, I decided to open up a new question on the subject because a) I'm not using NRPE with this check b) I tried the suggestions made on the earlier question to which I linked, but none of them worked. 在回顾了这个问题时 ,我遇到了几乎与check_url相同的问题,我决定打开一个关于这个问题的新问题因为a)我没有使用NRPE这个检查b)我尝试了对这个问题的建议我之前链接的问题,但没有一个有效。 For example... 例如...

./check_url some-domain.com | echo $0

returns "0" (which indicates the check was successful) 返回“0”(表示检查成功)

I then followed the debugging instructions on Nagios Suppor t to create a temp file called debug_check_url, and put the following in it (to then be called by my command definition): 然后我按照Nagios Suppor t上的调试说明创建一个名为debug_check_url的临时文件,并在其中加入以下内容(然后由我的命令定义调用):

#!/bin/sh
echo `date` >> /tmp/debug_check_url_plugin
echo $*  /tmp/debug_check_url_plugin
/usr/local/nagios/libexec/check_url $*

Assuming I'm not in "debugging mode", my command definition for running check_url is as follows (inside command.cfg): 假设我没有处于“调试模式”,我运行check_url的命令定义如下(在command.cfg中):

'check_url' command definition
define command{
       command_name    check_url
       command_line    $USER1$/check_url $url$
}

(Incidentally, you can also view what I was using in my service config file at the very bottom of this question) (顺便说一句,你也可以在我的服务配置文件中查看我在这个问题的最底部使用的内容)


Before publishing this question, however, I decided to give 1 more shot at figuring out a solution. 然而,在发布这个问题之前,我决定再一次尝试找出解决方案。 I found the check_url_status plugin, and decided to give that one a shot. 我找到了check_url_status插件,并决定给它一个镜头。 To do that, here's what I did: 要做到这一点,这就是我做的:

  1. mkdir /usr/lib/nagios/libexec/check_url_status/ mkdir / usr / lib / nagios / libexec / check_url_status /
  2. downloaded both check_url_status and utils.pm 同时下载了check_url_status和utils.pm
  3. Per the user comment / review on the check_url_status plugin page, I changed "lib" to the proper directory of /usr/lib/nagios/libexec/. 根据check_url_status插件页面上的用户评论/评论,我将“lib”更改为/ usr / lib / nagios / libexec /的正确目录。
  4. Run the following: 运行以下命令:

    ./check_user_status -U some-domain.com. ./check_user_status -U some-domain.com。 When I run the above command, I kept getting the following error: 当我运行上面的命令时,我不断收到以下错误:

bash-4.1# ./check_url_status -U mydomain.com Can't locate utils.pm in @INC (@INC contains: /usr/lib/nagios/libexec/ /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5) at ./check_url_status line 34. BEGIN failed--compilation aborted at ./check_url_status line 34. bash-4.1#。/ check_url_status -U mydomain.com找不到@INC中的utils.pm(@INC包含:/ usr / lib / nagios / libexec / / usr / local / lib / perl5 / usr / local / share / perl5 / usr / lib / perl5 / vendor_perl / usr / share / perl5 / vendor_perl / usr / lib / perl5 / usr / share / perl5)在./check_url_status第34行.BEGIN失败 - 编译在./check_url_status第34行中止。


So at this point, I give up, and have a couple of questions: 所以在这一点上,我放弃了,并提出了几个问题:

  1. Which of these two plugins would you recommend? 你会推荐这两个插件中的哪一个? check_url or check_url_status? check_url或check_url_status? (After reading the description of check_url_status, I feel that this one might be the better choice. Your thoughts?) (在阅读了check_url_status的描述后,我觉得这个可能是更好的选择。你的想法?)
  2. Now, how would I fix my problem with whichever plugin you recommended? 现在,我如何使用您推荐的插件解决我的问题?

At the beginning of this question, I mentioned I would include a small explanation of what I'm envisioning. 在这个问题的开头,我提到我会对我想象的内容做一个小小的解释。 I have a file called services.cfg which is where I have all of my service definitions located (imagine that!). 我有一个名为services.cfg的文件,这是我所有服务定义所在的位置(想象一下!)。

The following is a snippet of my service definition file, which I wrote to use check_url (because at that time, I thought everything worked). 以下是我的服务定义文件的片段,我写的是使用check_url(因为当时我认为一切正常)。 I'll build a service for each URL I want to monitor: 我将为我想要监控的每个URL构建一个服务:

###
# Monitoring Individual URLs...
#
###
define service{
        host_name                       {my-shared-web-server}
        service_description             URL: somedomain.com
        check_command                   check_url!somedomain.com
        max_check_attempts              5
        check_interval                  3
        retry_interval                  1
        check_period                    24x7
        notification_interval           30
        notification_period             workhours
}

I was making things WAY too complicated. 我让事情变得太复杂了。

The built-in / installed by default plugin, check_http, can accomplish what I wanted and more. 内置/安装的默认插件check_http可以实现我想要的功能和更多功能。 Here's how I have accomplished this: 这是我如何完成这个:

My Service Definition: 我的服务定义:

  define service{
            host_name                       myers
            service_description             URL: my-url.com
            check_command                   check_http_url!http://my-url.com
            max_check_attempts              5
            check_interval                  3
            retry_interval                  1
            check_period                    24x7
            notification_interval           30
            notification_period             workhours
    }

My Command Definition: 我的命令定义:

define command{
        command_name    check_http_url
        command_line    $USER1$/check_http -I $HOSTADDRESS$ -u $ARG1$
}

The better way to monitor urls is by using webinject which can be used with nagios. 监控网址的更好方法是使用可与nagios一起使用的webinject。

The below problem is due to the reason that you dont have the perl package utils try installing it. 以下问题是由于您没有perl包utils尝试安装它的原因。

bash-4.1# ./check_url_status -U mydomain.com Can't locate utils.pm in @INC (@INC contains: bash-4.1#。/ check_url_status -U mydomain.com无法在@INC中找到utils.pm(@INC包含:

You can make an script plugin. 你可以制作一个脚本插件。 It is easy, you only have to check the URL with something like: 这很容易,您只需要检查URL,例如:

`curl -Is $URL -k| grep HTTP | cut -d ' ' -f2`

$URL is what you pass to the script command by param. $ URL是您通过param传递给脚本命令的内容。

Then check the result: If you have an code greater than 399 you have a problem, else... everything is OK! 然后检查结果:如果你的代码大于399你就有问题,否则......一切都OK! THen an right exit mode and the message for Nagios. 这是一个正确的退出模式和Nagios的消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM