Seite wählen

NETWAYS Blog

Dynamische Formulare in Icinga Web 2

In meinem letzten internen Projekt der NETWAYS durfte ich ein Icinga Web 2 Module bauen, welches ein dynamisches Formular verwenden soll. Konkret sollte es mehrere Dropdown-Menüs geben, welche den Wert des vorherigen Dropdown-Menü evaluiert und anhand dessen, ein neues Dropdown befüllt. Dabei kann man zwei Herangehensweisen benutzen, welche ich im Folgenden erläutere.

Die klassische (schlechte) Herangehensweise

Die erste Möglichkeit, die mir in den Sinn kommt, ist, dass man sich über AJAX verschiedene Actions in Icinga Web 2 aufruft. Diese wiederum besitzen einen Code, der den Wert des zuvor ausgewählten Wertes evaluiert und das weitere Dropdown befüllt. Da Icinga Web 2 einem MVC (Modell, View, Controller) Muster folgt, wird ein Controller- für die Steuerung und ein View-Script für die Darstellung benötigt. Des Weiteren wird für den AJAX Request eine eigene module.js Datei benötigt, in der der JavaScript Code hinterlegt ist. Darüber hinaus müsste man noch CSS einbinden, damit das Formular auch noch schön dargestellt wird.

Alles im Allem, eine sehr sehr aufwendige Herangehensweise!

Die richtige Herangehensweise

Wie oben erwähnt, handelt es sich bei Icinga Web 2 um ein MVC, somit ist es auch möglich, bestimmte „ConfigForm-Views“ zu erstellen, die bereits alle benötigten Sachen zur Verfügung stellen: CSS, JavaScript und HTML. Das beste daran ist, dass dies super einfach zu implementieren ist und das Framework die ganze Arbeit von der „schlechten Herangehensweise“ übernimmt.
Man kann einer Configform die Klasse autosubmit mitgeben, dadurch erhält man ein Verhalten wie ein AJAX-Request. Im Folgenden ein kleiner Ausschnitt eines solchen ConfigControllers:

<?php
    namespace Icinga\Module\Testmodule\Forms\Test;
    use Icinga\Web\Form;
 
    class TestForm extends Form 
    {
      public function init()
      {
        $this->setName('form_test_form');
        $this->setSubmitLabel('Save Changes');
      }

      public function createElements(array $formData)
      {
          // Load cars
          $this->addElement(
              'select',
              'car',
              array(
                  'label' => $this->translate('Car'),
                  'multiOptions' => [
                      '' => '(select option)',
                      'audi' => 'Audi',
                      'vw' => 'VW'
                  ],
                  // 'autosubmit' acts like an AJAX-Request
                  'class' => 'autosubmit'
              )
          );

          // Select model
          if (isset($formData['car']) && $formData['car'] === 'audi') {
              $this->addElement(
                  'select',
                  'model',
                  array(
                      'label' => $this->translate('Model'),
                      'multiOptions' => [
                          '' => '(select model)',
                          'A1',
                          'A6'
                      ],
                      'required' => true,
                  )
              );
          } elseif (isset($formData['car']) && $formData['car'] === 'vw') {
              $this->addElement(
                  'select',
                  'model',
                  array(
                      'label' => $this->translate('Model'),
                      'multiOptions' => [
                          '' => '(select model)',
                          'Golf',
                          'Polo'
                      ],
                      'required' => true,
                  )
              );
          }
      }  
    }

Wenn man nun noch das View-Script einbindet erhält man eine Form, die wie folgt aussieht:



Durch das Framework von Icinga Web 2 ist es möglich, sehr schnell ein Modul nach eigenen Wünschen zu erstellen. Wem ich damit nun Lust auf ein bisschen Programmierung gemacht habe, dem kann ich die bereits vorhandenen Trainingsunterlagen auf Github empfehlen! Oder Ihr besucht eine unserer verschiedenen Konferenzen, bei der man auch mal detailliertere Einblicke wie z.B. Icinga Web 2 Modul Programmierung erhält.

Webinar am 10.02.2021: Icinga 2 kurz erklärt!

Am Mittwoch, den 10.02.2021 ist es soweit, wir bringen Euch ein Webinar zum Thema Icinga 2 Basics.

Anhand eines Walkthrough durch unsere Icinga Web 2 Demo-Oberfläche möchten wir Euch einen allgemeinen Überblick geben, was Icinga 2 für Euch tun kann. Es gibt einiges an Erweiterungen durch integrierte Module zu sehen sowie natürlich auch die richtigen Basics, die in keiner Umgebung fehlen sollten. Wir werden einen Blick werfen in das BusinessProcess Module, das vSphere Module und ins Reporting. Des Weiteren wollen wir Euch kurz Neuigkeiten zu Icinga for Windows mitgeben. Im Anschluss freuen wir uns auf Eure Fragen rund um das Thema Icinga 2, Icinga Web 2 und deren Features.

Wann und Wo

Los geht es am Mittwoch, den 10.02.2021 ab 10:30 Uhr auf dem NETWAYS Youtube Channel. Einfach rechtzeitig über diesen Link in den Stream kommen.

Wer es bis dahin nicht erwarten kann, dem empfehlen wir unsere vergangenen Webinare im Webinararchiv oder auf dem NETWAYS YouTube Channel. Dort können auch Videos der Vorträge unserer vergangenen Konferenzen abgerufen werden. Über anstehende Webinare könnt Ihr Euch immer hier informieren.

Apache Rewrite von HTTP auf HTTPS am Beispiel von Icinga Web 2

Heute gibt es einen kleinen Tipp, wie man seine über einen Apache ausgelieferten Seiten, von HTTP einfach auf HTTPS umleiten kann. Eine einfache Rewrite-Regel sorgt dafür, dass beliebige URLs korrekt auf HTTPS umgeleitet werden. So sind auch als HTTP-URLs gespeicherte Bookmarks weiterhin uneingeschränkt nutzbar. Voraussetzung ist das Laden der Modules rewrite.

Das nun folgende Beispiel bezieht sich auf die Default-Site, es kann aber leicht für weitere Sites abgewandelt werden. Hierzu ist das Beispiel um die Direktiven ServerName und optional ServerAlias zu ergänzen.


<VirtualHost *:80>
RewriteEngine on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>


<VirtualHost _default_:443>
SSLEngine on
Alias /icingaweb2 "/usr/share/icingaweb2/public"
...
</VirtualHost>

Alle weiteren für TLS und Icinga Web 2 nötigen Einstellungen wurden hier ausgelassen.

Lennart Betz
Lennart Betz
Senior Consultant

Der diplomierte Mathematiker arbeitet bei NETWAYS im Bereich Consulting und bereichert seine Kunden mit seinem Wissen zu Icinga, Nagios und anderen Open Source Administrationstools. Im Büro erleuchtet Lennart seine Kollegen mit fundierten geschichtlichen Vorträgen die seinesgleichen suchen.

Icinga 2 – Monitoring automatisiert mit Puppet Teil 14: Profile Part VI

Nachdem letzte Woche der Nginx verwendet wurde, wenden wir uns im nun vorerst letzten Teil der Konfiguration des Apaches als Webserver zur Auslieferung von Icinga Web 2 zu.
Der Apache kommt unter Debian als abhängig zu installierendes Paket von icingaweb2 mit und wird ensprechend konfiguriert. Damit dies unsere Anforderung an den Apache nicht wieder überschreibt, sorgen wir dafür, dass das Paket icingaweb2 vor der Klasse apache installiert wird. Hierfür müssen wir das Managment des Pakets durch die Klasse icingaweb2 unterbinden.
Damit das Icinga-Web-2-Modul für seine Konfigurationsdateien den korrekten Benutzer verwenden kann, ziehen wir diesen nach der Abarbeitung der Klasse apache aus dessen Modul.

 

[ruby]
if $web_server == ’nginx‘ {
[…]
} else {
#
# Apache
#
$manage_package = false
Package[‚icingaweb2‘]
-> Class[‚apache‘]
package { ‚icingaweb2‘:
ensure => installed,
}
class { ‚::apache‘:
default_mods => false,
default_vhost =>false,
mpm_module => ‚worker‘,
}
apache::listen { ’80‘: }
$web_conf_user = $::apache::user
include ::apache::mod::alias
include ::apache::mod::status
include ::apache::mod::dir
include ::apache::mod::env
include ::apache::mod::rewrite
include ::apache::mod::proxy
include ::apache::mod::proxy_fcgi
apache::custom_config { ‚icingaweb2‘:
ensure => present,
source => ‚puppet:///modules/icingaweb2/examples/apache2/for-mod_proxy_fcgi.conf‘,
verify_config => false,
priority => false,
}
}
[…]
[/ruby]

Der Apache wird von uns komplett mit allen Modulen für Icinga Web 2 verwaltet, da sich die Defaults für RedHat und Debian zu sehr unterscheiden. Auch hier, wie bei Nginx, entfernen wird alle Konfiguration sonstiger auszuliefernder Webseiten und benutzen die vom Icinga-Web-2-Modul zur Verfügung gestellt Beispielkonfiguration.

Lennart Betz
Lennart Betz
Senior Consultant

Der diplomierte Mathematiker arbeitet bei NETWAYS im Bereich Consulting und bereichert seine Kunden mit seinem Wissen zu Icinga, Nagios und anderen Open Source Administrationstools. Im Büro erleuchtet Lennart seine Kollegen mit fundierten geschichtlichen Vorträgen die seinesgleichen suchen.

OSMC 2018 – Day 2

The evening event was again great food, drinks and conversation and while it ended in the early morning for some people, rooms were full of attendees again for the first talk. It was a hard choice between probably great talks but in the end I had chosen Rodrigue Chakode with „Make IT monitoring ready for cloud-native systems„. Being a long-term contributor to several Open Source Monitoring he used his experience to develop Realopinsight as a tool bringing existing monitoring tools together and extending them for monitoring cloud-native application platforms. In his live demo he showed the webinterface and Icinga 2, Zabbix and Kubernetes integration including aggregation of the severity for a specific service across the different solutions.
OSMC 2018
Scoring a Technical Cyber Defense Exercise with Nagios and Selenium“ by Mauno Pihelgas was a quite uncommon case study. Locked Shields is the biggest Cyber Defense exercise involving 22 teams defending systems provided by vendors against hundreds of attacks. Mauno is responsible for the availability scoring system which gives the defending teams bonus points for availability of the systems, but of course it makes also available for attacks which if successful will cause loss of points. The data collected by Nagios and Selenium are then forwarded to Kafka and Elasticsearch to provide abuse control and overall scoring. To give you some numbers over the 2 days of the exercise about 34 million checks are executed and logged.
Susanne Greiner’s talk „Mit KI zu mehr Automatisierung bei der Fehleranalyse“ was on using Artificial Intelligence for automatic failure analyses. Her talk started from anomaly detection and forecasting, went through user experience and ended with machine learning and deep learning. It is always great to see what experts can do with data, so running anomaly detection and forecasting on the data, adding labels for user experience and feeding them to the AI can increase troubleshooting capabilities. And better troubleshooting will result in better availability and user experience of course what perhaps is the main goal of all IT.
At the evening event there was again some gambling and after lunch the guys how managed to win the most chips won some real prices.
OSMC 2018 Gambling Winners
While some still enjoyed the event massage, Carsten Köbke started the afternoon sessions with the best talk title „Katzeninhalt mit ein wenig Einhornmagie“ (Cat content with a little bit of unicorn magic). Being the author of the Icinga Web 2 module for Grafana and several themes for Icinga Web 2 he demonstrated and explained his work to the audience. It is very nice to see performance data with annotations extracted from the Icinga database nicely presented in Grafana. The themes part of the talk was based on the idea of every one can do this and monitoring can be fun.
Thomas and Daniel teamed up to focus on log management and help people on choosing their tool wisely in their talk „Fokus Log-Management: Wähle dein Werkzeug weise„. They compared the Elastic stack and Graylog with each other in multiple categories, showing up advantages and disadvantages and which tool fits best for which user group.
Eliminating Alerts or ‚Operation Forest‘“ by Rihards Olups was a great talk on how he tried reducing alerts to get a better acceptance and handling of the remaining alerts, getting problems solved instead of ignored. The ‚Operation forest‘ mentioned in the talk’s title is his synonym for there infrastructure and alerts are trash he does not like in his forest, because trash attracts trash, like alerts attract alerts because if the numbers grows they tend to be ignored and more problems will get critical causing more alerts. It is not a problem of the tool used for monitoring and alerting but he had not only nice hints on changing culture but also technical ones like focusing on one monitoring solution, knowing and using all features or making problems more recognizable like putting them into the message of the day. For those having the same problems in their environment he wrote a shitlist you can check the problems you have and the number of checked items will indicate how shitty your environment is, I recommend having a look at this list.
Last but not least Nicolai Buchwitz talked about the „Visualization of your distributed infrastructure“ and with his Map module for Icinga Web 2 he is providing a very powerful tool to visualize it. All the new features you get from the latest 1.1.0 release make it even more useful and the outlook on future extensions looks promising. Nicolai concluded with a nice live demo showing all this functionality.
So it was again a great conference, thanks to all speakers, attendees and sponsors for making this possible. I wish everyone not staying for the hackathon or Open Source camp „Save travels“. Slides, videos and pictures will be online in the near future. I hope to see you on next year’s OSMC on November, 4th – 7th!

Dirk Götz
Dirk Götz
Principal Consultant

Dirk ist Red Hat Spezialist und arbeitet bei NETWAYS im Bereich Consulting für Icinga, Puppet, Ansible, Foreman und andere Systems-Management-Lösungen. Früher war er bei einem Träger der gesetzlichen Rentenversicherung als Senior Administrator beschäftigt und auch für die Ausbildung der Azubis verantwortlich wie nun bei NETWAYS.