Icinga2: LiveStatus Activation/Installation

Hey all,

Here is a quick note how to install and activate MK Livestatus (Check_MK) API for your Icinga2 installation.

More info about livestatus on the official website: https://mathias-kettner.de/checkmk_livestatus.html

So, check if it’s already activated:

# icinga2 feature list
Disabled features: compatlog debuglog gelf graphite influxdb livestatus opentsdb perfdata statusdata syslog
Enabled features: api checker command ido-mysql mainlog notification

As we can see livestatus is currently disabled

Let’s enable it using the following command:

# icinga2 feature enable livestatus
Enabling feature livestatus. Make sure to restart Icinga 2 for these changes to take effect.

Now we need to add one more LivestatusListener object and fix the existing one to support livestatus on local unix socket and on TCP socket.

Open /etc/icinga2/features-enabled/livestatus.conf and edit it as following:

library "livestatus"

object LivestatusListener "livestatus-tcp" {
  socket_type = "tcp"
  bind_host = "0.0.0.0"
  bind_port = "6666"
}

object LivestatusListener "livestatus-unix" {
  socket_type = "unix"
  socket_path = "/var/run/icinga2/cmd/livestatus"
}

You can bind it to some specific IP and/or change port to another one if you need, also make sure that your socket_path is exists

# ls -la /var/run/icinga2/cmd/livestatus
srw-rw---- 1 icinga icingacmd 0 Oct 30 10:51 /var/run/icinga2/cmd/livestatus

Let me know if you have any questions

Thanks!

 

 

Icinga2 Director: How to import a server IP from local file

Hey all,

#shortstory

Today I had a pretty interesting task with Icinga2 and Director. The issue was with accessibility to DNS server which was installed in AWS without any public access, so basically it was used only for internal requests. To make story short, the task was to get IP address from local file, hostname from SQL database and assign it to each other.

Here is the changes that I made for ‘PropertyModifierGetHostByName.php’ file.

<?php

// - /usr/share/icingaweb2/modules/director/library/Director/PropertyModifier/PropertyModifierGetHostByName.php
namespace Icinga\Module\Director\PropertyModifier;

use Icinga\Exception\InvalidPropertyException;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;

class PropertyModifierGetHostByName extends PropertyModifierHook
{
    public static function addSettingsFormFields(QuickForm $form)
    {
        $form->addElement('select', 'on_failure', array(
            'label'        => 'On failure',
            'description'  => $form->translate('What should we do if the host (DNS) lookup fails?'),
            'multiOptions' => $form->optionalEnum(array(
                'null' => $form->translate('Set no value (null)'),
                'keep' => $form->translate('Keep the property (hostname) as is'),
                'fail' => $form->translate('Let the whole import run fail'),
            )),
            'required'    => true,
        ));
    }

    public function getName()
    {
        return 'Get host by name (DNS lookup)';
    }

    public function transform($value)
    {
        //$host = gethostbyname($value);
        $lines_array = file("/usr/share/icingaweb2/dns.txt"); //comma-separated txt file
        
        foreach($lines_array as $line) {
            if(strpos($line, $value) !== false) {
            list(, $new_str) = explode(",", $line);
            $host = trim($new_str); }
        }

        if (strlen(@inet_pton($host)) !== 4) {
            switch ($this->getSetting('on_failure')) {
                case 'null':
                    return null;
                case 'keep':
                    return $value;
                case 'fail':
                default:
                    throw new InvalidPropertyException(
                        'Host lookup failed for "%s"',
                        $value
                    );
            }
        }

        return $host;
    }
}

The file dns.txt contains IP and domain names, which are comma-separated. You may change the location of the file, use many of them, or even use key-value database for such queries, it’s pretty easy.

So, basically it search for IP address in dns.txt file for provided hostname in Import function. It will return null or fail (based on your settings), if returned IP is not IPv4.

Extra module will be created and pushed to the github on next Monday.

Happy monitoring!

 

Garage Sale – new or like-new books on Sale!

Learning Python, 5th Editionby Mark Lutz

Get a comprehensive, in-depth introduction to the core Python language with this hands-on book. Based on author Mark Lutz’s popular training course, this updated fifth edition will help you quickly write efficient, high-quality code with Python. It’s an ideal way to begin, whether you’re new to programming or a professional developer versed in other languages.

Complete with quizzes, exercises, and helpful illustrations, this easy-to-follow, self-paced tutorial gets you started with both Python 2.7 and 3.3 the latest releases in the 3.X and 2.X lines plus all other releases in common use today. You’ll also learn some advanced language features that recently have become more common in Python code.

  • Explore Python’s major built-in object types such as numbers, lists, and dictionaries
  • Create and process objects with Python statements, and learn Python’s general syntax model
  • Use functions to avoid code redundancy and package code for reuse
  • Organize statements, functions, and other tools into larger components with modules
  • Dive into classes: Python’s object-oriented programming tool for structuring code
  • Write large programs with Python’s exception-handling model and development tools
  • Learn advanced Python tools, including decorators, descriptors, metaclasses, and Unicode processing

Price: $60

Amazon: https://www.amazon.com/Learning-Python-5th-Mark-Lutz/dp/1449355730/

Learning Python
Learning Python

Read more under cut…

Continue reading “Garage Sale – new or like-new books on Sale!”