Thruk is an advanced interface for Nagios (and Shinken) that allows connecting to multiple Nagios instances simultaneously and displaying more relevant information compared to the standard Nagios interface.
For Thruk configuration, there are 2 important files:
thruk.conf: General configuration
thruk_local.conf: Custom configuration
According to the official documentation, it’s preferable not to touch the general configuration and override certain parameters with the custom configuration.
Here’s a basic configuration to make it work with MK Livestatus:
############################################
# put your own settings into this file
# settings from this file will override
# those from the thruk.conf
############################################
# Interface Options
default_theme = Exfoliation
use_timezone = CET
use_ajax_search = 1
use_new_search = 1
info_popup_event_type = onmouseover
show_modified_attributes = 1
show_long_plugin_output = inline
show_full_commandline = 2
# Backends to Mklivestatus
<Component Thruk::Backend>
<peer>
name = Local Nagios
type = livestatus
<options>
peer = /var/lib/nagios3/rw/live
resource_file = /etc/nagios3/resource.cfg
</options>
<configtool>
core_conf = /etc/nagios3/nagios.cfg
obj_check_cmd = /usr/sbin/nagios3 -v /etc/nagios3/nagios.cfg
obj_reload_cmd = /etc/init.d/nagios3 reload
</configtool>
</peer>
</Component>
You can add multiple Peers to have a unified interface with several Nagios servers. Once you have access to the Thruk interface, you can configure all its options directly from this interface, as well as those of Nagios.
Then reload Apache for the changes to take effect.
I had already discussed in the Nagios documentation solutions for having a fairly minimal screen. The problem is that it’s still not sufficient, and fortunately with Thruk there’s a way to fix this issue without having to recode 3/4 of the program. So I created a small patch that I submitted to the Thruk team (which has just been accepted https://github.com/sni/Thruk/commit/d1eefef82cd8fbab6ebebff8a570bb1e026d1a9f but will only be available in the next release (1.28)), so in the meantime, here’s how to have the most minimal interface possible.
Here is a first patch to modify the Thruk Perl modules so that they take into account a new parameter in the URL called “minimal”:
In some cases, you may have certain checks that temporarily store information on the Nagios server, and you want to be able to execute actions from the Nagios interface. For this, there is the ‘action_url’ option where we can provide a URL to a CGI that will execute what we want, possibly with options.
Let’s start by creating our CGI. Here is a minimalist example where I remove a temporary file:
#!/usr/bin/perluseCGI;
$query=CGI::new();
$host=$query->param("host");
# Avoid inputing special characters that would crash the programif ( $h=~ /\`|\~|\@|\#|\$|\%|\^|\&|\*|\(|\)|\:|\=|\+|\"|\'|\;|\<|\>/ ) {
print"Illegal special chars detected. Exit\n";
exit(1);
}
print"Content-type: text/html\n\n";
print"<HTML>\n";
print"<HEAD><Title>Removing $host temporary file</Title>\n";
print"<LINK REL='stylesheet' TYPE='text/css' HREF='/nagios/stylesheets/common.css'><LINK REL='stylesheet' TYPE='text/css' HREF='/nagios/stylesheets/status.css'>\n";
print"</HEAD><BODY>\n";
print"Removing $host Interface Network Flapping temporary file...";
if (-f"/tmp/iface_state_$host.txt")
{
unlink("/tmp/iface_state_$host.txt") orprint"FAIL<br />/tmp/iface_state_$host.txt : $!\n"andexit(1);
print"OK\n";
}
else{
print"FAIL<br />/tmp/iface_state_$host.txt : No such file or directory\n";
}
print"</body></html>\n";
And then in the configuration of the service in question, I insert my ‘action_url’:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
define service{
use generic-services-ulsysnet
hostgroup_name network
service_description Interface Network Flapping
check_period 24x7
notification_period 24x7
_SNMP_PORT 161
_SNMP_COMMUNITY public
_DURATION 86400
check_command check_interface_flapping
# For Thruk & Nagios
# action_url ../../cgi-bin/nagios3/remove.cgi?host=$HOSTADDRESS$
# For Nagios only
action_url remove.cgi?host=$HOSTADDRESS$
}
Now you just need to reload Nagios.
You’ll notice that for Thruk, I found an easy but not very clean method, which consists of rewriting the URL to point to the Nagios links. For a clean method, you would need to write a dedicated plugin.