jjethwa / icinga2

GNU General Public License v3.0
223 stars 189 forks source link

Icinga2 External Script #42

Closed manhdinh closed 8 years ago

manhdinh commented 8 years ago

Hello everyone. In Zabbix, i used external script resolve some personal requires. Are there any ways to use scripts in ICinga2?

jjethwa commented 8 years ago

Hi @manhdinh

Yes, you can! :) Here's a link to the documentation to get you started: http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/monitoring-basics#commands

In terms of the container, you would need to use a volume for your configurations (/etc/icinga2), database (/var/lib/mysql) and then make the scripts available via another volume.

manhdinh commented 8 years ago

Firstly, thanks for your reply. Can you demonstrate your way more detail?. Hosnetly, I don't understand your method. If possible, can you make a very simple example?

jjethwa commented 8 years ago

Hi @manhdinh

No problem :) I'll try my best, but it might be a little hard over text hehe

You might want to take a look at Icinga Director. It's pre-installed in my container and makes configuring things a lot easier: https://github.com/Icinga/icingaweb2-module-director

To setup your scripts manually:

The first thing to check is to make sure your scripts are set up to output in the right format: http://docs.icinga.org/latest/en/pluginapi.html

For my example, I'll use one of the existing scripts, check_http, available from The Monitoring Plugins Project: https://www.monitoring-plugins.org/doc/man/check_http.html

  1. Configure a new CheckCommand in Icinga2: http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/monitoring-basics?highlight-search=check_http#command-arguments

This configuration basically tells Icinga2 where to find the script, what arguments the script accepts, and finally, default arguments to pass to the script if none are passed.

  1. Define a Service

Let's say we want to use the check_http command to check for the presence of a string across all of our apache servers

apply Service "apache_healthcheck" {
  import "generic-service"

  display_name = "Apache health check"

  check_command = "check_http"
  vars.sla = "24x7"

  vars.http_warn_time = 5
  vars.http_critical_time = 10
  vars.expect_string = 200
  vars.http_uri = "/path/to/healthcheck.html"
  vars.http_port = "$host.vars.http_port$"
  vars.check_string = "foo"

  assign where "apache-servers" in host.groups
}

This configuration will apply this service check to every server in the apache-servers group (you can also just map it to any host object that has the http_port variable defined...lots of options here depending on your setup)

Hopefully that helps you a little bit. Our team set up several POCs (including Zabbix) and Icinga2 came out on top. The configuration syntax is extremely powerful and the Icinga Web 2 interface is beautiful, works on all devices, and shows you exactly what you need to worry about :)

manhdinh commented 8 years ago

Thanks alot. :) But acctually my mean about "external script" is not the way that you describe. My problem is that i want to monitor the size of table in Mysql database : http://prntscr.com/bxlwu5 . My idea is use external script to monitor dbsize, but quite confuse about the method to configure https://exchange.nagios.org/directory/Plugins/Databases/SQLServer/Check-SQL-Database-Size-(with-NRPE)/details

jjethwa commented 8 years ago

Hi @manhdinh

The method I described would be used to add a new check executed from the icinga2 server. Are you asking about how to add a check executed via nrpe?

jjethwa commented 8 years ago

No response from user, so I'm closing this issue. Please re-open it if you need further support :)