Benutzer-Werkzeuge

Webseiten-Werkzeuge


tachtler:icinga2_-_api-zugriff_apache

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
tachtler:icinga2_-_api-zugriff_apache [2018/10/23 12:56] klaustachtler:icinga2_-_api-zugriff_apache [2018/10/23 13:45] (aktuell) – [/etc/httpd/conf.d/httpd-vhost.conf] klaus
Zeile 35: Zeile 35:
 Die [[https://www.icinga.org/|Icinga]]2-**API** benötigt entweder "basic auth" oder Client-Zertifikate für die Authentifizierung. Die [[https://www.icinga.org/|Icinga]]2-**API** benötigt entweder "basic auth" oder Client-Zertifikate für die Authentifizierung.
  
-Nachfolgende **API-User**-Berechtigungen werden entsprechend den Anforderungen festgelegt. Standardmäßig werden nur Daten von den Endpunkten ''/v1/status'' und ''/v1/objects'' abgerufen, und daher werden auch  keine Schreibberechtigungen benötigt.+Nachfolgende **API-User**-Berechtigungen werden entsprechend den Anforderungen festgelegt. Standardmäßig werden nur Daten von den Endpunkten ''/v1/status'' und ''/v1/objects'' abgerufen
 + 
 +:!: **HINWEIS** - **Je nach verwendeter Abfrage-Softwarez.B.** 
 +  * [[https://github.com/bashgeek/icinga-multi-status|Icinga Multi Status (Browser Plugin)]] oder 
 +  * [[http://damien.degois.info/android/aNag/|aNag - (Android App)]] 
 +**müssen die Berechtigungen ggfsehr weitreichend sein !!!**
  
 Nachfolgende Ergänzungen in den Konfigurationsdatei ''/etc/icinga2/conf.d/api-users.conf'' müssen **am Ende der Konfigurationsdatei angehängt werden**, damit zur [[https://www.icinga.org/|Icinga]]2-Konfiguration ein neues **API-User-Objekt** hinzugefügt wird: Nachfolgende Ergänzungen in den Konfigurationsdatei ''/etc/icinga2/conf.d/api-users.conf'' müssen **am Ende der Konfigurationsdatei angehängt werden**, damit zur [[https://www.icinga.org/|Icinga]]2-Konfiguration ein neues **API-User-Objekt** hinzugefügt wird:
Zeile 78: Zeile 83:
 Hinzufügen eines neuen neues **API-User-Objekts** zur [[https://www.icinga.org/|Icinga]]2-Konfiguration. Hinzufügen eines neuen neues **API-User-Objekts** zur [[https://www.icinga.org/|Icinga]]2-Konfiguration.
  
-:!: **HINWEIS** - **Je nach verwendeter Abfrage-Software, z.B.** +==== icinga2: Features ==== 
-  * [[https://github.com/bashgeek/icinga-multi-status|Icinga Multi Status (Browser Plugin)]] oder + 
-  * [[http://damien.degois.info/android/aNag/|aNag (Android App)]] +Nachfolgend ist sicher zu stellen, dass auch das entsprechende **Feature** in [[https://www.icinga.org/|Icinga]]2 aktiv (**enabled**) ist. Nachfolgender Befehl zeigt, wie dies überprüft werden kann: 
-**müssen die Berechtigungen ggfsehr weitreichend sein !!!**+<code> 
 +# icinga2 feature list 
 +Disabled features: debuglog elasticsearch gelf influxdb livestatus opentsdb perfdata 
 +Enabled features: api checker command compatlog graphite ido-mysql mainlog notification statusdata syslog 
 +</code> 
 + 
 +:!: **WICHTIG** - Das **Feature** - **''api''** muss bei **''Enabled features:''** gelistet sein! 
 + 
 +Falls dies nicht der Fall sein sollte, kann dies mit nachfolgendem Befehl nachgeholt werden: 
 +<code> 
 +# icinga2 feature enable api 
 +</code> 
 + 
 +==== icinga2: Neustart ==== 
 + 
 +Danach kann der **icinga2**-Server mit nachfolgendem Befehle **neu** gestartet werden: 
 +<code> 
 +# systemctl restart icinga2 
 +</code> 
 + 
 +Mit nachfolgendem Befehl kann der Status des [[https://www.icinga.org/|Icinga]]-Servers abgefragt werden: 
 +<code> 
 +# systemctl status icinga2.service 
 +● icinga2.service - Icinga host/service/network monitoring system 
 +   Loaded: loaded (/usr/lib/systemd/system/icinga2.service; enabled; vendor preset: disabled) 
 +   Active: active (running) since Mon 2016-12-26 10:53:37 CET; 16s ago 
 +  Process: 32190 ExecStart=/usr/sbin/icinga2 daemon -d -e ${ICINGA2_ERROR_LOG} (code=exited, status=0/SUCCESS) 
 +  Process: 32127 ExecStartPre=/usr/lib/icinga2/prepare-dirs /etc/sysconfig/icinga2 (code=exited, status=0/SUCCESS) 
 + Main PID: 32221 (icinga2) 
 +   CGroup: /system.slice/icinga2.service 
 +           ├─32212 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon -... 
 +           └─32221 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon -... 
 + 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:36 server11.idmz.tachtler.net icinga2[32190]: [2016-12-26 10:53:... 
 +Dec 26 10:53:37 server11.idmz.tachtler.net systemd[1]: Started Icinga host/se... 
 +Hint: Some lines were ellipsized, use -l to show in full. 
 +</code> 
 + 
 +Nachfolgende LOG-Dateien sollten Auskunft darüber geben, wie der Start und der Status des [[https://www.icinga.org/|Icinga]]-Servers ist. 
 +  * ''/var/log/icinga2/icinga2.log'' 
 +  * ''/var/log/icinga2/error.log'' 
 + 
 +Die LOG-Datei ''/var/log/icinga2/error.log'' sollte hingegen **leer** sein! 
 + 
 +===== Konfiguration ===== 
 + 
 +Nachfolgend die **VHOST**-Konfiguration für den [[http://httpd.apache.org/|Apache HTTP Server]]. 
 + 
 +:!: **WICHTIG** - **Nachfolgende Konfigurationen stellen eine grundlegende [[http://httpd.apache.org/|Apache HTTP Server]]-VHOST-Konfiguration dar.\\ Weitere Einzelheiten zu [[http://httpd.apache.org/|Apache HTTP Server]]-VHOST sind in der Dokumentation zum [[http://httpd.apache.org/|Apache HTTP Server]] verfügbar!** 
 + 
 +==== /etc/httpd/conf.d/httpd-vhost.conf ==== 
 + 
 +Nachfolgend ein Beispiel für einen [[http://httpd.apache.org/|Apache HTTP Server]]-VHOST via **https**: 
 +<code apache> 
 +
 +# VirtualHost HTTPS 
 +
 +<VirtualHost *:443> 
 +        ServerAdmin hostmaster@tachtler.net 
 +        ServerName icingaapiaccess.tachtler.net 
 +        ServerPath / 
 + 
 +        # ---------------------------------------------------------- 
 +        # HTTPS settings 
 +        # ---------------------------------------------------------- 
 +        SSLEngine on 
 +        SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 
 +        SSLHonorCipherOrder on 
 +        SSLCipherSuite "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:!aNULL:!MD5:!DSS" 
 +        SSLCertificateFile /etc/pki/tls/cert.pem 
 +        SSLCertificateKeyFile /etc/pki/tls/private.pem 
 +        SSLCertificateChainFile /etc/pki/tls/chain.pem 
 +        SSLCACertificateFile /etc/pki/tls/fullchain.pem 
 + 
 +        # ---------------------------------------------------------- 
 +        # Location settings 
 +        # ---------------------------------------------------------- 
 +        <Location /> 
 +        </Location> 
 +         
 +        # ---------------------------------------------------------- 
 +        # Proxy settings 
 +        # ---------------------------------------------------------- 
 +        SSLProxyEngine on 
 + 
 +        SSLProxyVerify none 
 +        SSLProxyCheckPeerCN off 
 +        SSLProxyCheckPeerName off 
 +        SSLProxyCheckPeerExpire off 
 +        SSLProxyProtocol all -SSLv3 -SSLv2 
 +        ProxyTimeout 1200 
 + 
 +        ProxyRequests Off 
 +        ProxyPreserveHost On 
 +        ProxyPass / https://localhost:5665/ retry=0 timeout=300 keepalive=on 
 +        ProxyPassReverse / https://localhost:5665/ 
 + 
 +        # ---------------------------------------------------------- 
 +        # Logging settings 
 +        # ---------------------------------------------------------- 
 +        ErrorLog "logs/error_log" 
 +        CustomLog "logs/access_log" combined 
 +</VirtualHost> 
 + 
 +</code> 
 + 
 +==== Icinga2: API-Test ==== 
 + 
 +:!: **WICHTIG** - Bei der Konfiguration ist darauf zu achten, dass die [[https://icinga.com/docs/icinga2/latest/doc/12-icinga2-api/|Icinga2 API]] unter nachfolgender URL zu erreichen ist: 
 +  * [[https://localhost:5665]] 
 + 
 +Dies kann durch ausführen von nachfolgendem Befehl ausprobiert werden: 
 +<code html> 
 +# curl -k -s -u apiuser:auchgeheim 'https://localhost:5665/v1' 
 +<html><head><title>Icinga 2</title></head><h1>Hello from Icinga 2 (Version: r2.10.1-1)!</h1><p> 
 +You are authenticated as <b>apiuser</b>. Your user has the following permissions:</p> <ul><li>*</li></ul> 
 +<p>More information about API requests is available in the <a href="https://docs.icinga.com/icinga2/latest" 
 +target="_blank">documentation</a>.</p></html> 
 +</code> 
 + 
 +==== Apache: Neustart ==== 
 + 
 +Nach Durchführung der vorhergehenden **Konfigurationsschritte**, sollte einem **Neustart** nichts im Wege stehen und die **Apache VHOST-Konfiguration** angezogen werden: 
 +<code> 
 +# systemctl restart httpd.service 
 +</code> 
 + 
 +:!: **HINWEIS** - **Es erfolgen __keine__ weiteren Ausgaben, wenn der Start erfolgreich war !** 
 + 
 +==== Apache: API-Abfrage ==== 
 + 
 +Nun sollte die [[https://icinga.com/docs/icinga2/latest/doc/12-icinga2-api/|Icinga2 API]] unter nachfolgender URL zu erreichen ist: 
 +  * [[https://icingaapiaccess.tachtler.net/v1]] 
 + 
 +Dies kann durch ausführen von nachfolgendem Befehl ausprobiert werden: 
 +<code html> 
 +# curl -k -s -u apiuser:auchgeheim 'https://icingaapiaccess.tachtler.net/v1' 
 +<html><head><title>Icinga 2</title></head><h1>Hello from Icinga 2 (Version: r2.10.1-1)!</h1><p> 
 +You are authenticated as <b>apiuser</b>. Your user has the following permissions:</p> <ul><li>*</li></ul> 
 +<p>More information about API requests is available in the <a href="https://docs.icinga.com/icinga2/latest" 
 +target="_blank">documentation</a>.</p></html> 
 +</code>
  
tachtler/icinga2_-_api-zugriff_apache.1540292189.txt.gz · Zuletzt geändert: 2018/10/23 12:56 von klaus