Add LINE Notify Alert Transport. (#10495)

* Add LINE Notify Alert Transport.

* Fix code style.

* Update document.

* Update Linenotify.php
This commit is contained in:
Shao Yu-Lung (Allen)
2019-09-05 12:30:53 +08:00
committed by Tony Murray
parent 48a07ada6a
commit 9ac70037bb
2 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
/**
* LINE Notify Transport
* @package LibreNMS
* @subpackage Alerts
*/
namespace LibreNMS\Alert\Transport;
use LibreNMS\Alert\Transport;
class Linenotify extends Transport
{
public function deliverAlert($obj, $opts)
{
$opts['line-notify-access-token'] = $this->config['line-notify-access-token'];
return $this->contactLineNotify($obj, $opts);
}
private function contactLinenotify($obj, $opts)
{
$lineUrl = 'https://notify-api.line.me/api/notify';
$lineHead = ['Authorization: Bearer ' . $opts['line-notify-access-token']];
$lineFields = ['message' => $obj['msg']];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $lineUrl);
curl_setopt($curl, CURLOPT_HTTPHEADER, $lineHead);
curl_setopt($curl, CURLOPT_NOBODY, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $lineFields);
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($code != 200) {
return 'HTTP Status code ' . $code;
}
return true;
}
public static function configTemplate()
{
return [
'config' => [
[
'title' => 'Token',
'name' => 'line-notify-access-token',
'descr' => 'LINE Notify Token',
'type' => 'text'
]
],
'validation' => [
'line-notify-access-token' => 'required|string',
]
];
}
}

View File

@@ -288,6 +288,18 @@ LibreNMS database.
| Jira Username | myjirauser |
| Jira Password | myjirapass |
## LINE Notify
[LINE Notify](https://notify-bot.line.me/)
[LINE Notify API Document](https://notify-bot.line.me/doc/)
**Example:**
| Config | Example |
| ------ | ------- |
| Token | AbCdEf12345 |
## Mail
For all but the default contact, we support setting multiple email