mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
Merge pull request #2082 from PandaWawawa/issue-2079
Add unmute alert function
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
- [`alerts`](#api-alerts)
|
- [`alerts`](#api-alerts)
|
||||||
- [`get_alert`](#api-route-12)
|
- [`get_alert`](#api-route-12)
|
||||||
- [`ack_alert`](#api-route-13)
|
- [`ack_alert`](#api-route-13)
|
||||||
|
- [`unmute_alert`](#api-route-24)
|
||||||
- [`list_alerts`](#api-route-14)
|
- [`list_alerts`](#api-route-14)
|
||||||
- [`rules`](#api-rules)
|
- [`rules`](#api-rules)
|
||||||
- [`get_alert_rule`](#api-route-15)
|
- [`get_alert_rule`](#api-route-15)
|
||||||
@@ -591,6 +592,33 @@ Output:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name="api-route-24">Function: `unmute_alert`</a> [`top`](#top)
|
||||||
|
|
||||||
|
Unmute an alert
|
||||||
|
|
||||||
|
Route: /api/v0/alerts/unmute/:id
|
||||||
|
|
||||||
|
- id is the alert id, you can obtain a list of alert ids from [`list_alerts`](#api-route-14).
|
||||||
|
|
||||||
|
Input:
|
||||||
|
|
||||||
|
-
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```curl
|
||||||
|
curl -X PUT -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/alerts/unmute/1
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
```text
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"err-msg": "",
|
||||||
|
"message": "Alert has been unmuted"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### <a name="api-route-14">Function: `list_alerts`</a> [`top`](#top)
|
### <a name="api-route-14">Function: `list_alerts`</a> [`top`](#top)
|
||||||
|
|
||||||
List all alerts
|
List all alerts
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ $app->group(
|
|||||||
// api/v0/alerts
|
// api/v0/alerts
|
||||||
$app->put('/:id', 'authToken', 'ack_alert')->name('ack_alert');
|
$app->put('/:id', 'authToken', 'ack_alert')->name('ack_alert');
|
||||||
// api/v0/alerts/$id (PUT)
|
// api/v0/alerts/$id (PUT)
|
||||||
|
$app->put('/unmute/:id', 'authToken', 'unmute_alert')->name('unmute_alert');
|
||||||
|
// api/v0/alerts/unmute/$id (PUT)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$app->get('/alerts', 'authToken', 'list_alerts')->name('list_alerts');
|
$app->get('/alerts', 'authToken', 'list_alerts')->name('list_alerts');
|
||||||
|
|||||||
@@ -795,7 +795,39 @@ function ack_alert() {
|
|||||||
$app->response->setStatus($code);
|
$app->response->setStatus($code);
|
||||||
$app->response->headers->set('Content-Type', 'application/json');
|
$app->response->headers->set('Content-Type', 'application/json');
|
||||||
echo _json_encode($output);
|
echo _json_encode($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmute_alert() {
|
||||||
|
global $config;
|
||||||
|
$app = \Slim\Slim::getInstance();
|
||||||
|
$router = $app->router()->getCurrentRoute()->getParams();
|
||||||
|
$alert_id = mres($router['id']);
|
||||||
|
$status = 'error';
|
||||||
|
$err_msg = '';
|
||||||
|
$message = '';
|
||||||
|
$code = 500;
|
||||||
|
if (is_numeric($alert_id)) {
|
||||||
|
$status = 'ok';
|
||||||
|
$code = 200;
|
||||||
|
if (dbUpdate(array('state' => 1), 'alerts', '`id` = ? LIMIT 1', array($alert_id))) {
|
||||||
|
$message = 'Alert has been unmuted';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message = 'No alert by that ID';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$err_msg = 'Invalid alert has been provided';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = array(
|
||||||
|
'status' => $status,
|
||||||
|
'err-msg' => $err_msg,
|
||||||
|
'message' => $message,
|
||||||
|
);
|
||||||
|
$app->response->setStatus($code);
|
||||||
|
$app->response->headers->set('Content-Type', 'application/json');
|
||||||
|
echo _json_encode($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user