Skip to content

Commit

Permalink
Merge pull request #64 from Icinga/feature/add-duedate
Browse files Browse the repository at this point in the history
Feature/add duedate

closes #37
  • Loading branch information
theFeu authored May 20, 2021
2 parents d72dd91 + 186f6e0 commit 815d746
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Changes
* FIX: we're sending Content-Length to make proxies happy (#51)
* FEATURE: Show status for created issues (#44)
* FEATURE: Allow choosing a default template (#36)
* FEATURE: Add configurable duedate for created JIRA issues (#37)

### v1.0.1

Expand Down
7 changes: 7 additions & 0 deletions application/clicommands/SendCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class SendCommand extends Command
* OPTIONAL
*
* --service <service-name> Icinga Service name
* --due-date <due-date> When the Jira ticket is to be due.
* It can be a date or time difference in textual datetime format.
* --template <template-name> Template name (templates.ini section)
* --ack-author <author> Username shown for acknowledgements,
* defaults to "JIRA"
Expand All @@ -57,6 +59,7 @@ public function problemAction()
$ackPipe = $p->shift('command-pipe');
$status = $p->shiftRequired('state');
$description = $p->shiftRequired('description');
$duedate = $p->shift('due-date');

$jira = $this->jira();
$issue = $jira->eventuallyGetLatestOpenIssueFor($host, $service);
Expand All @@ -74,6 +77,7 @@ public function problemAction()
'state' => $status,
'host' => $host,
'service' => $service,
'duedate' => $duedate
] + $p->getParams();

$template = new IssueTemplate();
Expand All @@ -83,6 +87,9 @@ public function problemAction()
$info = new MonitoringInfo($host, $service);
$info->setNotificationType('PROBLEM'); // TODO: Once passed, we could deal with RECOVERY
$template->setMonitoringInfo($info);
if (! empty($duedate)) {
$template->addFields(['duedate' => $duedate]);
}

$key = $jira->createIssue($template->getFilled($params));

Expand Down
1 change: 1 addition & 0 deletions doc/03-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ SearchCategory = "CI"
SearchTerm = "${host}.example.com"
Activity.value = "proactive"
customfield_1232 = "Icinga"
duedate = "3 days"
```

Pass `my-workflow` to your NotificationCommand through the `--template` parameter
Expand Down
6 changes: 5 additions & 1 deletion library/Jira/IssueTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public function getFilled($params)
{
$fields = [];
foreach ($this->getUnfilledFields() as $key => $tpl) {
$this->addToFields($fields, $key, $this->fillTemplate($tpl, $params));
if ($key === 'duedate') {
$fields['duedate'] = date('Y-m-d', strtotime($tpl));
} else {
$this->addToFields($fields, $key, $this->fillTemplate($tpl, $params));
}
}

if (isset($fields['description'])) {
Expand Down
1 change: 1 addition & 0 deletions library/Jira/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public function fetchIssues($host = null, $service = null, $onlyOpen = true)
'summary',
'status',
'created',
'duedate',
'icingaStatus',
'icingaKey',
];
Expand Down

0 comments on commit 815d746

Please sign in to comment.