Added transport modules Kayako Classic and SMSFeedback (#9027)

Hello! I've made a first version of Alert Transporting module for Kayako Classic Servicedesk. May be it is possible to use with Kayako OnPremise version (not sure).

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
Alexey Medvedev
2018-08-22 00:41:59 +03:00
committed by Neil Lathwood
parent d83b675090
commit e448190a68
4 changed files with 262 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.com>
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
namespace LibreNMS\Alert\Transport;
use LibreNMS\Alert\Transport;
class Kayako extends Transport
{
public function deliverAlert($host, $kayako)
{
if (!empty($this->config)) {
$kayako['url'] = $this->config['kayako-url'];
$kayako['key'] = $this->config['kayako-key'];
$kayako['secret'] = $this->config['kayako-secret'];
$kayako['department'] = $this->config['kayako-department'];
}
return $this->contactKayako($host, $kayako);
}
public function contactKayako($host, $kayako)
{
global $config;
$url = $kayako['url']."/Tickets/Ticket";
$key = $kayako['key'];
$secret = $kayako['secret'];
$user = $config['email_from'];
$department = $kayako['department'];
$ticket_type= 1;
$ticket_status = 1;
$ticket_prio = 1;
$salt = mt_rand();
$signature = base64_encode(hash_hmac('sha256', $salt, $secret, true));
$protocol = array(
'subject' => ($host['name'] ? $host['name'] . ' on ' . $host['hostname'] : $host['title']),
'fullname' => 'LibreNMS Alert',
'email' => $user,
'contents' => strip_tags($host['msg']),
'departmentid' => $department,
'ticketstatusid' => $ticket_status,
'ticketpriorityid' => $ticket_prio,
'tickettypeid' => $ticket_type,
'autouserid' => 1,
'ignoreautoresponder' => true,
'apikey' => $key,
'salt' => $salt,
'signature' => $signature
);
$post_data = http_build_query($protocol, '', '&');
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code != 200) {
var_dump("Kayako returned Error, retry later");
return false;
}
return true;
}
public static function configTemplate()
{
return [
'config' => [
[
'title' => 'Kayako URL',
'name' => 'kayako-url',
'descr' => 'ServiceDesk API URL',
'type' => 'text'
],
[
'title' => 'Kayako API Key',
'name' => 'kayako-key',
'descr' => 'ServiceDesk API Key',
'type' => 'text'
],
[
'title' => 'Kayako API Secret',
'name' => 'kayako-secret',
'descr' => 'ServiceDesk API Secret Key',
'type' => 'text'
],
[
'title' => 'Kayako Department',
'name' => 'kayako-department',
'descr' => 'Department to post a ticket',
'type' => 'text'
]
],
'validation' => [
'kayako-url' => 'required|url',
'kayako-key' => 'required|string',
'kayako-secret' => 'required|string',
'kayako-department' => 'required|string'
]
];
}
}

View File

@@ -0,0 +1,106 @@
<?php
/* Copyright (C) 2015 Daniel Preussker <f0o@librenms.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/**
* SMSEagle API Transport
* @author Barry O'Donovan <barry@lightnet.ie>
* @copyright 2017 Barry O'Donovan, LibreNMS
* @license GPL
* @package LibreNMS
* @subpackage Alerts
*/
namespace LibreNMS\Alert\Transport;
use LibreNMS\Alert\Transport;
class Smsfeedback extends Transport
{
public function deliverAlert($obj, $opts)
{
if (empty($this->config)) {
return $this->deliverAlertOld($obj, $opts);
}
$smsfeedback_opts['user'] = $this->config['smsfeedback-user'];
$smsfeedback_opts['token'] = $this->config['smsfeedback-pass'];
$smsfeedback_opts['sender'] = $this->config['smsfeedback-sender'];
$smsfeedback_opts['to'] = $this->config['smsfeedback-mobiles'];
return $this->contactsmsfeedback($obj, $smsfeedback_opts);
}
public function deliverAlertOld($obj, $opts)
{
return $this->contactsmsfeedback($obj, $opts);
}
public static function contactsmsfeedback($obj, $opts)
{
$params = [
'login' => $opts['user'],
'pass' => md5($opts['token']),
'phone' => $opts['to'],
'text' => $obj['title'],
'sender' => $opts['sender'],
];
$url = 'http://' . $opts['user'] . ':' . $opts['token'] . '@' . 'api.smsfeedback.ru/messages/v2/send/?' . http_build_query($params);
$curl = curl_init($url);
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($curl);
if (substr($ret, 0, 8) == "accepted") {
return true;
}
}
public static function configTemplate()
{
return [
'config' => [
[
'title' => 'User',
'name' => 'smsfeedback-user',
'descr' => 'smsfeedback User',
'type' => 'text',
],
[
'title' => 'Password',
'name' => 'smsfeedback-pass',
'descr' => 'smsfeedback Password',
'type' => 'text',
],
[
'title' => 'Mobiles',
'name' => 'smsfeedback-mobiles',
'descr' => 'smsfeedback Mobile number',
'type' => 'textarea',
],
[
'title' => 'Sender',
'name' => 'smsfeedback-sender',
'descr' => 'smsfeedback sender name',
'type' => 'textarea',
],
],
'validation' => [
'smsfeedback-user' => 'required|string',
'smsfeedback-pass' => 'required|string',
'smsfeedback-mobiles' => 'required',
'smsfeedback-sender' => 'required|string',
]
];
}
}

View File

@@ -440,3 +440,44 @@ sending the alerts such as librenms. I.e:
| Config | Example |
| ------ | ------- |
| Post URL | https://alert.victorops.com/integrations/generic/20132414/alert/2f974ce1-08fc-4dg8-a4f4-9aee6cf35c98/librenms |
## Kayako Classic
LibreNMS can send alerts to Kayako Classic API which are then converted to tickets.
To use this module, you need REST API feature enabled in Kayako Classic and configured email account at LibreNMS. To enable this, do this:
AdminCP -> REST API -> Settings -> Enable API (Yes)
Also you need to know the department id to provide tickets to appropriate department and a user email to provide, which is used as ticket author.
To get department id: navigate to appropriate department name at the departments list page in Admin CP and watch the number at the end of url.
Example: http://servicedesk.example.com/admin/Base/Department/Edit/17. Department ID is 17
As a requirement, you have to know API Url, API Key and API Secret to connect to servicedesk
[Kayako REST API Docs] (https://classic.kayako.com/article/1502-kayako-rest-api)
**Example:**
| Config | Example |
| ------ | ------- |
| Kayako URL | http://servicedesk.example.com/api/ |
| Kayako API Key | 8cc02f38-7465-4a0c-8730-bb3af122167b |
| Kayako API Secret | Y2NhZDIxNDMtNjVkMi0wYzE0LWExYTUtZGUwMjJiZDI0ZWEzMmRhOGNiYWMtNTU2YS0yODk0LTA1MTEtN2VhN2YzYzgzZjk5 |
| Kayako Department | 1 |
## SMSFeedback
SMSFeedback is a SAAS service, which can be used to deliver Alerts via API, using API url, Username & Password.
They can be in international dialling format only.
[SMSFeedback Api Docs](https://www.smsfeedback.ru/smsapi/)
**Example:**
| Config | Example |
| ------ | ------- |
| User | smsfeedback_user |
| Password | smsfeedback_password |
| Mobiles | 71234567890 |
| Sender name| CIA |

View File

@@ -50,6 +50,7 @@ if (Auth::user()->hasGlobalAdmin()) {
<option value="hipchat-form">Hipchat</option>
<option value="irc-form">IRC</option>
<option value="jira-form">Jira</option>
<option value="kayako-form">Kayako Classic</option>
<option value="mail-form" selected>Mail</option>
<option value="msteams-form">Microsoft Teams</option>
<option value="nagios-form">Nagios</option>
@@ -62,6 +63,7 @@ if (Auth::user()->hasGlobalAdmin()) {
<option value="rocket-form">Rocket.chat</option>
<option value="slack-form">Slack</option>
<option value="smseagle-form">SMSEagle</option>
<option value="smsfeedback-form">SMSFeedback</option>
<option value="syslog-form">Syslog</option>
<option value="telegram-form">Telegram</option>
<option value="victorops-form">Victorops</option>