From 73f34e7f29469dd6f98c72678079b93d2148e6ed Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 5 Feb 2016 16:37:57 +0100 Subject: [PATCH] host/agent: agent setup instructions, with ticket --- application/controllers/HostController.php | 25 ++++++- application/views/scripts/host/agent.phtml | 82 ++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 application/views/scripts/host/agent.phtml diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index dc3b4d34..a84ec432 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Controllers; +use Icinga\Module\Director\Util; use Icinga\Module\Director\Web\Controller\ObjectController; class HostController extends ObjectController @@ -10,11 +11,21 @@ class HostController extends ObjectController { parent::init(); if ($this->object) { - $this->getTabs()->add('services', array( + $tabs = $this->getTabs(); + $tabs->add('services', array( 'url' => 'director/host/services', 'urlParams' => array('name' => $this->object->object_name), 'label' => 'Services' )); + if ($this->object->object_type === 'object' + && $this->object->getResolvedProperty('has_agent') === 'y' + ) { + $tabs->add('agent', array( + 'url' => 'director/host/agent', + 'urlParams' => array('name' => $this->object->object_name), + 'label' => 'Agent' + )); + } } } @@ -25,4 +36,16 @@ class HostController extends ObjectController $this->view->table = $this->loadTable('IcingaService')->enforceFilter('host_id', $this->object->id)->setConnection($this->db()); $this->render('objects/table', null, true); } + + public function agentAction() + { + $this->getTabs()->activate('agent'); + $this->view->title = 'Agent deployment instructions'; + // TODO: Fail when no ticket + $this->view->certname = $this->object->object_name; + $this->view->ticket = Util::getIcingaTicket($this->view->certname, $this->api()->getTicketSalt()); + $this->view->master = 'master'; // TODO: Change this!! + $this->view->masterzone = 'master'; + $this->view->globalzone = 'director-global'; + } } diff --git a/application/views/scripts/host/agent.phtml b/application/views/scripts/host/agent.phtml new file mode 100644 index 00000000..ddf09a8e --- /dev/null +++ b/application/views/scripts/host/agent.phtml @@ -0,0 +1,82 @@ +
+tabs ?> +

escape($this->title) ?>

+
+ +
+escape($this->certname); +$master = $this->escape($this->master); +?> +

When using the node wizard

+

Ticket salt: escape($ticket) ?>

+

Linux commandline

+

Just copy & paste this script (and please scroll down for a corresponding icinga2.cfg):

+
+#!/bin/bash
+
+# TODO, Eventually:
+# apt-get install --no-install-recommends icinga2 nagios-plugins
+# or yum install ...
+
+# This generates and signs your required certificates
+
+ICINGA_PKI_DIR=/etc/icinga2/pki
+ICINGA_USER=nagios
+chown $ICINGA_USER $ICINGA_PKI_DIR
+
+icinga2 pki new-cert --cn  \
+--key $ICINGA_PKI_DIR/.key \
+--cert $ICINGA_PKI_DIR/.crt
+
+icinga2 pki save-cert --key $ICINGA_PKI_DIR/.key \
+--trustedcert $ICINGA_PKI_DIR/trusted-master.crt \
+--host  
+
+icinga2 pki request --host  \
+--port 5665 \
+--ticket escape($ticket) ?> \
+--key $ICINGA_PKI_DIR/.key \
+--cert $ICINGA_PKI_DIR/.crt \
+--trustedcert $ICINGA_PKI_DIR/trusted-master.crt \
+--ca $ICINGA_PKI_DIR/ca.crt
+
+ +

/etc/icinga2/icinga2.conf

+
+/** Icinga 2 Config - proposed by Icinga Director */
+
+include "constants.conf"
+include <itl>
+include <plugins>
+include <plugins-contrib>
+
+object FileLogger "main-log" {
+  severity = "information"
+  path = LocalStateDir + "/log/icinga2/icinga2.log"
+}
+
+// TODO: improve establish connection handling
+object Endpoint "" {}
+object Endpoint "" {}
+object Zone "" {
+  endpoints = [ "" ]
+  // TODO: all endpoints in master zone
+}
+
+object Zone "" { global = true }
+
+object Zone "" {
+  parent = ""
+  endpoints = [ "" ]
+}
+
+object ApiListener "api" {
+  cert_path = SysconfDir + "/icinga2/pki/.crt"
+  key_path = SysconfDir + "/icinga2/pki/.key"
+  ca_path = SysconfDir + "/icinga2/pki/ca.crt"
+  accept_commands = true
+  accept_config = true
+}
+
+