summaryrefslogtreecommitdiffstats
path: root/library/Generictts/Ticket.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:20:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:20:19 +0000
commit7b64af59410f1a658c70b8be367156fc3f4da17c (patch)
tree367fc1ef06004119d3941460a22c4f83b1ca4d7d /library/Generictts/Ticket.php
parentInitial commit. (diff)
downloadicingaweb2-module-generictts-7b64af59410f1a658c70b8be367156fc3f4da17c.tar.xz
icingaweb2-module-generictts-7b64af59410f1a658c70b8be367156fc3f4da17c.zip
Adding upstream version 2.1.0.upstream/2.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Generictts/Ticket.php')
-rw-r--r--library/Generictts/Ticket.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/library/Generictts/Ticket.php b/library/Generictts/Ticket.php
new file mode 100644
index 0000000..b8ded1d
--- /dev/null
+++ b/library/Generictts/Ticket.php
@@ -0,0 +1,71 @@
+<?php
+
+/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Generictts;
+
+use Icinga\Application\Config;
+use Icinga\Application\Hook\TicketHook;
+
+/**
+ * GenericTTS TicketHook implementation
+ */
+class Ticket extends TicketHook
+{
+ /**
+ * GenericTTS configuration
+ *
+ * @var \Icinga\Application\Config
+ */
+ protected $config;
+
+ /**
+ * Configured trouble ticket system integrations
+ *
+ * @var \Icinga\Application\Hook\Ticket\TicketPattern[]
+ */
+ protected $ticketPatterns;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function init()
+ {
+ $config = Config::module('generictts');
+ $this->config = $config;
+
+ $ticketPatterns = array();
+ foreach ($config as $section => $values) {
+ if ($values->get('url')) { // Skip integrations that don't contain a URL
+ $ticketPattern = $this->createTicketPattern($section, $values->get('pattern'));
+ if ($ticketPattern->isValid()) { // Skip integrations that don't contain a pattern
+ $ticketPatterns[$section] = $ticketPattern;
+ }
+ }
+ }
+ $this->ticketPatterns = $ticketPatterns;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @return \Icinga\Application\Hook\Ticket\TicketPattern[]
+ */
+ public function getPattern()
+ {
+ return $this->ticketPatterns;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function createLink($match)
+ {
+ /** @var \Icinga\Application\Hook\Ticket\TicketPattern $match */
+ return sprintf(
+ '<a href="%s" target="_blank">%s</a>',
+ preg_replace('/\$1/', rawurlencode($match[1]), $this->config->get($match->getName(), 'url')),
+ $match[0]
+ );
+ }
+}