mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add LINE Notify Alert Transport. (#10495)
* Add LINE Notify Alert Transport. * Fix code style. * Update document. * Update Linenotify.php
This commit is contained in:
committed by
Tony Murray
parent
48a07ada6a
commit
9ac70037bb
57
LibreNMS/Alert/Transport/Linenotify.php
Normal file
57
LibreNMS/Alert/Transport/Linenotify.php
Normal 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',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user