summaryrefslogtreecommitdiffstats
path: root/library/Generictts/Ticket.php
diff options
context:
space:
mode:
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]
+ );
+ }
+}