librenms-librenms/html/includes/print-alert-transports.php

168 lines
6.4 KiB
PHP
Raw Normal View History

Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
<?php
use LibreNMS\Authentication\LegacyAuth;
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
$no_refresh = true;
?>
<div class="row">
<div class="col-sm-12">
<span id="message"></span>
</div>
</div>
<?php
require_once 'includes/modal/edit_alert_transport.inc.php';
require_once 'includes/modal/edit_transport_group.inc.php';
?>
<div class="table-responsive">
<table class="table table-hover table-condensed">
<tr>
<th>#</th>
<th>Transport Name</th>
<th>Transport Type</th>
<th>Default</th>
<th>Details</th>
<th style="width:126px;">Action</th>
</tr>
<td colspan="6">
<?php
if (LegacyAuth::user()->hasGlobalAdmin()) {
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#edit-alert-transport'><i class='fa fa-plus'></i> Create alert transport</button>";
}
echo "</td>";
// Iterate through each alert transport
$query = "SELECT `transport_id` AS `id`, `transport_name` AS `name`, `transport_type` AS `type`, `is_default`, `transport_config` AS `config` FROM `alert_transports`";
foreach (dbFetchRows($query) as $transport) {
echo "<tr id=\"alert-transport-{$transport['id']}\">";
echo "<td><i>#".((int)$transport['id'])."</i></td>";
echo "<td>".$transport['name']."</td>";
echo "<td>".$transport['type']."</td>";
if ($transport['is_default'] == true) {
echo "<td>Yes</td>";
} else {
echo "<td>No</td>";
}
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
echo "<td class='col-sm-4'>";
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
// Iterate through transport config template to display config details
$class = 'LibreNMS\\Alert\\Transport\\'.ucfirst($transport['type']);
if (!method_exists($class, 'configTemplate')) {
//skip
continue;
}
$tmp = call_user_func($class.'::configTemplate');
$transport_config = json_decode($transport['config'], true);
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
foreach ($tmp['config'] as $item) {
if ($item['type'] == 'oauth') {
continue;
}
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
$val = $transport_config[$item['name']];
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
// Match value to key name for select inputs
if ($item['type'] == 'select') {
$val = array_search($val, $item['options']);
}
echo "<i>".$item['title'].": ".$val."<br/></i>";
}
echo "</td>";
echo "<td>";
// Add action buttons for admin users only
if (Auth::user()->hasGlobalAdmin()) {
echo "<div class='btn-group btn-group-sm' role='group'>";
echo "<button type='button' class='btn btn-primary' data-toggle='modal' data-target='#edit-alert-transport' data-transport_id='".$transport['id']."' name='edit-alert-rule' data-container='body' data-toggle='popover' data-content='Edit transport'><i class='fa fa-lg fa-pencil' aria-hidden='true'></i></button> ";
echo "<button type='button' class='btn btn-danger' aria-label='Delete' data-toggle='modal' data-target='#delete-alert-transport' data-transport_id='".$transport['id']."' name='delete-alert-transport' data-container='body' data-toggle='popover' data-content='Delete transport'><i class='fa fa-lg fa-trash' aria-hidden='true'></i></button>";
echo "<button type='button' class='btn btn-warning' data-transport_id='".$transport['id']."' data-transport='{$transport['type']}' name='test-transport' id='test-transport' data-toggle='popover' data-content='Test transport'><i class='fa fa-lg fa-check' aria-hidden='true'></i></button> ";
echo "</div>";
}
echo "</td>";
echo "</tr>\r\n";
}
?>
</table>
</div>
<div class="table-responsive">
<table class="table table-hover table-condensed">
<tr>
<th>#</th>
<th>Transport Group</th>
<th>Size</th>
<th>Members</th>
<th style="width:86px;">Action</th>
</tr>
<td colspan="5">
<?php
if (Auth::user()->hasGlobalAdmin()) {
echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#edit-transport-group'><i class='fa fa-plus'></i> Create transport group</button>";
}
echo "</td>";
//Iterate through alert groups
$query = "SELECT `transport_group_id` AS `id`, `transport_group_name` AS `name` FROM `alert_transport_groups`";
foreach (dbFetchRows($query) as $group) {
echo "<tr id=\"alert-transport-group-{$group['id']}\">";
echo "<td><i>#".((int)$group['id'])."</i></td>";
echo "<td>".$group['name']."</td>";
//List out the members of each group
$query = "SELECT `transport_type`, `transport_name` FROM `transport_group_transport` AS `a` LEFT JOIN `alert_transports` AS `b` ON `a`.`transport_id`=`b`.`transport_id` WHERE `transport_group_id`=?";
$members = dbFetchRows($query, [$group['id']]);
echo "<td>".sizeof($members)."</td>";
echo "<td>";
foreach ($members as $member) {
echo "<i>".ucfirst($member['transport_type']).": ".$member['transport_name']."<br /></i>";
}
echo "</td>";
echo "<td>";
if (Auth::user()->hasGlobalAdmin()) {
echo "<div class='btn-group btn-group-sm' role='group'>";
echo "<button type='button' class='btn btn-primary' data-toggle='modal' data-target='#edit-transport-group' data-group_id='".$group['id']."' data-container='body' data-toggle='popover' data-content='Edit transport group'><i class='fa fa-lg fa-pencil' aria-hidden='true'></i></button> ";
echo "<button type='button' class='btn btn-danger' aria-label='Delete' data-toggle='modal' data-target='#delete-transport-group' data-group_id='".$group['id']."' data-container='body' data-toggle='popover' data-content='Delete transport group'><i class='fa fa-lg fa-trash' aria-hidden='true'></i></button>";
echo "</div>";
}
echo "</td>";
echo "</tr>";
}
?>
</table>
</div>
<script>
$("button#test-transport").click(function() {
var $this = $(this);
var transport_id = $this.data("transport_id");
var transport = $this.data("transport");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "test-transport", transport_id: transport_id },
dataType: "json",
success: function(data){
if (data.status === 'ok') {
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
toastr.success('Test to ' + transport + ' ok');
} else {
toastr.error('Test to ' + transport + ' failed<br />' + data.message);
Added Alert Transports Mapping (#8660) Hello all, I guess this is the second version of a more fully fleshed out alert contact mapping feature. The old one was GH-8507 Transports to convert: - [x] API - [x] Cisco Spark - [x] Elasticsearch - [x] GitLab - [x] Philips Hue - [x] Jira - [x] Mail - [ ] ~~PagerDuty~~ - Requires a callback so leaving for now - [x] Nagios - [x] IRC - [x] Discord - [x] Rocket.chat - [x] Hipchat - [x] Pushover - [x] Boxcar - [x] Telegram - [x] Pushbullet - [x] VictorOps - [x] OpsGenie - [x] Clickatell - [x] PlaySMS - [x] Canopsis - [x] osTicket - [x] Microsoft Teams - [x] SMSEagle - [x] Syslog - [x] Slack The intention is for this feature to have three different levels to it: 1. Alert rule to an alert contact mapping (where the code is at now) 2. Alert rule to an alert group (made up of alert contacts) mapping 3. Alert contact mapping to different transport configurations. There will be three transport configuration types. 1. Default (the configuration that is held in the configs table) 2. None (no transport configuration - will explain later) 3. Other (a configuration that will be defined in a different able) Take Mail transport for example. It can either be of a "default" or "other" configuration. The hope is that in the future, users can send mail from different mail servers if they wish. However, for ciscospark which requires a room ID and an api-token, I've decided that it has no transport configuration. Most likely, every alert contact will contain a different room-id and an api-token - which is why it has the transport config of "none". For other transports : I am not familiar with them, so hopefully the community can add support for these. I can definitely help! To add support for each transport will require several things: - addition to the UI - addition to forms/alert-contacts.inc.php - modifications to its object class Screenshots ![image](https://user-images.githubusercontent.com/28970851/39594533-2092ce9e-4eca-11e8-9c5d-cd002ece1425.png) ![image](https://user-images.githubusercontent.com/28970851/39594544-276e9856-4eca-11e8-80cc-82789ee0b2b2.png) ![image](https://user-images.githubusercontent.com/28970851/39594553-2fdf528c-4eca-11e8-8a40-4f149e767054.png) I'm not sure if this is the best way to do things, so please let me know if there's a better way to structure the code! Any comments on code/db schema,/UI etc is welcome and encouraged! The UI is heavily based on alert rules (front end is not my strong suit). And parts of the code are based on the code that was written for alert rules. 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`
2018-07-21 13:34:59 -06:00
}
},
error: function(){
toastr.error('Test to ' + transport + ' failed - general error');
}
});
});
$("[data-toggle='popover']").popover({
trigger: 'hover',
placement: 'top'
});
</script>