Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions application/forms/Config/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ protected function assemble()
}
]
]
)->addElement(
'text',
'icingaKeyPrefix',
[
'label' => 'icingaKeyPrefix',
'description' => $this->translate(
'Custom name that is prefixed to the icingaKey, If you plan to have multiple individual '
. 'icinga instances write to the same jira project you should set a meaningful name her like cluster1'
),
'required' => false,
]
);

// Fieldset for UI
Expand Down
5 changes: 5 additions & 0 deletions doc/03-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ following JQL construct:
A little bit weird, but it should work fine. And as this field is usually not
shown anywhere, it shouldn't disturb.

If you also set the icingaKeyPrefix to something that is not `''` like `cluster1` your JQL construct
will look like this:

icingaKey ~ "\"BEGIN_cluster1_example.com!Disk SpaceEND\""

## Fill Jira Custom Fields

For your customized workflows you might need this module to ship additional
Expand Down
22 changes: 16 additions & 6 deletions library/Jira/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,36 @@ private function finalizeIssueQuery(string $query, $host = null, $service = null

$config = Config::module('jira');
$keyField = $config->get('key_fields', 'icingaKey', 'icingaKey');
$prefix = $config->get('key_fields', 'icingaKeyPrefix', '');

if ($host === null) {
$query .= ' AND ' . $keyField . ' ~ "BEGIN*"';
$pattern = 'BEGIN*';
if ($prefix !== '') {
$pattern = 'BEGIN_' . $prefix . '_*';
}
} else {
$icingaKey = static::makeIcingaKey($host, $service);

$pattern = static::makeIcingaKey($host, $service);
// There is no exact field matcher out of the box on Jira, this is
// an ugly work-around. We search for "BEGINhostnameEND" or
// "BEGINhostname!serviceEND"
$query .= \sprintf(' AND ' . $keyField . ' ~ "\"%s\""', $icingaKey);
// an ugly work-around. We search for "BEGINhostnameEND" or "BEGIN_YOURPREFIX_hostname"
// "BEGINhostname!serviceEND" or "BEGIN_YOURPREFIX_hostname!serviceEND"

}

$query .= \sprintf(" AND '$keyField'" . ' ~ "\"%s\""', $pattern);

$query .= ' ORDER BY created DESC';

return $query;
}

public static function makeIcingaKey($host, $service = null)
{
$prefix = Config::module('jira')->get('key_fields', 'icingaKeyPrefix', '');
$icingaKey = "BEGIN$host";
if ($prefix !== '') {
$icingaKey = "BEGIN_{$prefix}_{$host}";
}

if ($service !== null) {
$icingaKey .= "!$service";
}
Expand Down
9 changes: 7 additions & 2 deletions library/Jira/Web/Table/IssueDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ protected function assemble()
$fields = $issue->fields;
$projectKey = $fields->project->key;
$keyField = $config->get('key_fields', 'icingaKey', 'icingaKey');

$icingaKey = preg_replace('/^BEGIN(.+)END$/', '$1', $fields->$keyField);
$prefix = $config->get('key_fields', 'icingaKeyPrefix','');
$pattern = '/^BEGIN(.+)END$/';
if($prefix !== ''){
$pattern = '/^BEGIN_' . $prefix . '_(.+)END$/';
}

$icingaKey = preg_replace($pattern, '$1', $fields->$keyField);
$parts = explode('!', $icingaKey);
$host = array_shift($parts);
$helper->setHostName($host);
Expand Down