Get data from rundeck webhook notification and send to mattermost.
<?php | |
/* | |
* ProudCommerce | 2019 | |
* www.proudcommerce.com | |
* | |
* https://docs.mattermost.com/developer/webhooks-incoming.html | |
* https://github.com/ThibaudDauce/mattermost-php | |
*/ | |
require __DIR__ . '/vendor/autoload.php'; | |
use GuzzleHttp\Client; | |
use ThibaudDauce\Mattermost\Mattermost; | |
use ThibaudDauce\Mattermost\Message; | |
use ThibaudDauce\Mattermost\Attachment; | |
// get rundeck data | |
$rawData = file_get_contents('php://input'); | |
$rawData = str_replace('"', '', $rawData); | |
if(!empty($rawData)) { | |
$parsedData = simplexml_load_string($rawData); | |
$name = $parsedData->executions->execution->job->name; | |
$description = $parsedData->executions->execution->job->description; | |
$url = $parsedData->executions->execution->attributes()['href']; | |
if(!empty($name) && !empty($description) && !empty($url)) { | |
$mattermost = new Mattermost(new Client, 'YOUR_MATTERMOST_WEBHOOK_URL'); | |
$message = (new Message) | |
->text('') | |
->channel('YOUR_MATTERMOST_CHANNEL') | |
->username('rundeck') | |
->iconUrl('YOUR_MATTERMOST_ICON_URL/rundeck.png') | |
->attachment(function (Attachment $attachment) { | |
global $name, $description, $url; | |
$attachment->error() | |
->text("**FAILED ".$name."**\r\n".$description."\r\n".$url); | |
}); | |
$mattermost->send($message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment