Skip to content

Commit

Permalink
accept and resolve ops
Browse files Browse the repository at this point in the history
  • Loading branch information
krystianity committed May 12, 2023
1 parent 87e4a93 commit 22b4bf9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ilert-rust CHANGELOG

## 2023-05-13, Version 3.1.0

* added alert accept and resolve operations

## 2023-05-12, Version 3.0.0

* updated dependencies
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ilert"
version = "3.0.0"
version = "3.1.0"
authors = ["Christian Froehlingsdorf <chris@ilert.com>"]
edition = "2021"
description = "The official ilert api bindings."
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ client
"Host srv/mail01 is CRITICAL", None)
.execute();

// accept alert

let accept_result = client
.update()
.accept_alert(123)
.execute()
.unwrap();

// resolve alert

let resolve_result = client
.update()
.resolve_alert(123)
.execute()
.unwrap();

// fetch users

let user_result = client
Expand Down
2 changes: 1 addition & 1 deletion src/ilert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl ILert {

fn get_default_headers() -> HeaderMap {
let mut headers = HeaderMap::new();
headers.append("User-Agent", HeaderValue::from_str("ilert-rust/3.0.0").unwrap());
headers.append("User-Agent", HeaderValue::from_str("ilert-rust/3.1.0").unwrap());
headers.append("Accept", HeaderValue::from_str("application/json").unwrap());
headers.append("Content-Type", HeaderValue::from_str("application/json").unwrap());
headers
Expand Down
12 changes: 12 additions & 0 deletions src/ilert_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ pub trait AlertGetApiResource {
pub trait AlertPutApiResource {
// alert_raw() leaving alert() open for a typed implementation
fn alert_raw(&mut self, id: i64, entity: &serde_json::Value) -> Box<&dyn BaseRequestExecutor>;
fn accept_alert(&mut self, id: i64) -> Box<&dyn BaseRequestExecutor>;
fn resolve_alert(&mut self, id: i64) -> Box<&dyn BaseRequestExecutor>;
}

/* ### INCIDENTS ### */
Expand Down Expand Up @@ -735,6 +737,16 @@ impl AlertPutApiResource for PutRequestBuilder<'_> {
self.builder.set_body(entity.to_string().as_str());
Box::new(self)
}

fn accept_alert(&mut self, id: i64) -> Box<&dyn BaseRequestExecutor> {
self.builder.set_path(format!("/alerts/{}/accept", id).as_str());
Box::new(self)
}

fn resolve_alert(&mut self, id: i64) -> Box<&dyn BaseRequestExecutor> {
self.builder.set_path(format!("/alerts/{}/resolve", id).as_str());
Box::new(self)
}
}

impl IncidentPutApiResource for PutRequestBuilder<'_> {
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ mod tests {
use serde_json::json;

use crate::ilert::ILert;
use crate::ilert_builders::{UserGetApiResource, EventApiResource, ScheduleGetApiResource,
HeartbeatApiResource, ILertEventType, ILertPriority, EventImage,
EventComment, AlertGetApiResource};
use crate::ilert_builders::{UserGetApiResource, EventApiResource, ScheduleGetApiResource, HeartbeatApiResource, ILertEventType, ILertPriority, EventImage, EventComment, AlertGetApiResource, AlertPutApiResource};

#[test]
fn init() -> () {
Expand All @@ -25,7 +23,7 @@ mod tests {
let mut client = ILert::new_with_opts(Some("http://localhost:8080"), Some(10)).unwrap();
client.auth_via_user("chris@chris", "chris").unwrap();

let mut user_result = client
let user_result = client
.get()
.skip(0)
.limit(10)
Expand All @@ -42,7 +40,7 @@ mod tests {
let mut client = ILert::new_with_opts(Some("http://localhost:8080"), Some(10)).unwrap();
client.auth_via_user("chris@chris", "chris").unwrap();

let mut alert_result = client
let alert_result = client
.get()
.skip(0)
.limit(10)
Expand Down

0 comments on commit 22b4bf9

Please sign in to comment.