Struct kuma_client::Client

source ·
pub struct Client { /* private fields */ }
Expand description

A client for interacting with Uptime Kuma.

Example:

// Connect to the server
let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");
 
// Create a tag
let tag_definition = client
    .add_tag(TagDefinition {
        name: Some("example_tag".to_owned()),
        color: Some("red".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to add tag");
 
// Create a group
let group = client
    .add_monitor(MonitorGroup {
        name: Some("Example Group".to_owned()),
        tags: vec![Tag {
            tag_id: tag_definition.tag_id,
            value: Some("example_group".to_owned()),
            ..Default::default()
        }],
        ..Default::default()
    })
    .await
    .expect("Failed to add group");
 
// Createa a notification
let notification = client
    .add_notification(Notification {
        name: Some("Example Notification".to_owned()),
        config: Some(serde_json::json!({
            "webhookURL": "https://webhook.site/304eeaf2-0248-49be-8985-2c86175520ca",
            "webhookContentType": "json"
        })),
        ..Default::default()
    })
    .await
    .expect("Failed to add notification");
 
// Create a monitor
client
    .add_monitor(MonitorHttp {
        name: Some("Monitor Name".to_owned()),
        url: Some("https://example.com".to_owned()),
        parent: group.common().id().clone(),
        tags: vec![Tag {
            tag_id: tag_definition.tag_id,
            value: Some("example_monitor".to_owned()),
            ..Default::default()
        }],
        notification_id_list: Some(
            vec![(
                notification.id.expect("No notification ID").to_string(),
                true,
            )]
            .into_iter()
            .collect(),
        ),
        ..Default::default()
    })
    .await
    .expect("Failed to add monitor");
 
let monitors = client.get_monitors().await.expect("Failed to get monitors");
println!("{:?}", monitors);

Implementations§

source§

impl Client

source

pub async fn connect(config: Config) -> Result<Client>

Examples found in repository?
examples/get_monitors.rs (lines 5-10)
4
5
6
7
8
9
10
11
12
13
14
15
16
async fn main() {
    let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");

    let monitors = client.get_monitors().await.expect("Failed to get monitors");
    println!("{:?}", monitors);
}
More examples
Hide additional examples
examples/create_monitor.rs (lines 11-16)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
async fn main() {
    // Connect to the server
    let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");

    // Create a tag
    let tag_definition = client
        .add_tag(TagDefinition {
            name: Some("example_tag".to_owned()),
            color: Some("red".to_owned()),
            ..Default::default()
        })
        .await
        .expect("Failed to add tag");

    // Create a group
    let group = client
        .add_monitor(MonitorGroup {
            name: Some("Example Group".to_owned()),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_group".to_owned()),
                ..Default::default()
            }],
            ..Default::default()
        })
        .await
        .expect("Failed to add group");

    // Createa a notification
    let notification = client
        .add_notification(Notification {
            name: Some("Example Notification".to_owned()),
            config: Some(serde_json::json!({
                "webhookURL": "https://webhook.site/304eeaf2-0248-49be-8985-2c86175520ca",
                "webhookContentType": "json"
            })),
            ..Default::default()
        })
        .await
        .expect("Failed to add notification");

    // Create a monitor
    client
        .add_monitor(MonitorHttp {
            name: Some("Monitor Name".to_owned()),
            url: Some("https://example.com".to_owned()),
            parent: group.common().id().clone(),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_monitor".to_owned()),
                ..Default::default()
            }],
            notification_id_list: Some(
                vec![(
                    notification.id.expect("No notification ID").to_string(),
                    true,
                )]
                .into_iter()
                .collect(),
            ),
            ..Default::default()
        })
        .await
        .expect("Failed to add monitor");

    let monitors = client.get_monitors().await.expect("Failed to get monitors");
    println!("{:?}", monitors);
}
source

pub async fn get_monitors(&self) -> Result<MonitorList>

Retrieves a list of monitors from Uptime Kuma.

Examples found in repository?
examples/get_monitors.rs (line 14)
4
5
6
7
8
9
10
11
12
13
14
15
16
async fn main() {
    let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");

    let monitors = client.get_monitors().await.expect("Failed to get monitors");
    println!("{:?}", monitors);
}
More examples
Hide additional examples
examples/create_monitor.rs (line 81)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
async fn main() {
    // Connect to the server
    let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");

    // Create a tag
    let tag_definition = client
        .add_tag(TagDefinition {
            name: Some("example_tag".to_owned()),
            color: Some("red".to_owned()),
            ..Default::default()
        })
        .await
        .expect("Failed to add tag");

    // Create a group
    let group = client
        .add_monitor(MonitorGroup {
            name: Some("Example Group".to_owned()),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_group".to_owned()),
                ..Default::default()
            }],
            ..Default::default()
        })
        .await
        .expect("Failed to add group");

    // Createa a notification
    let notification = client
        .add_notification(Notification {
            name: Some("Example Notification".to_owned()),
            config: Some(serde_json::json!({
                "webhookURL": "https://webhook.site/304eeaf2-0248-49be-8985-2c86175520ca",
                "webhookContentType": "json"
            })),
            ..Default::default()
        })
        .await
        .expect("Failed to add notification");

    // Create a monitor
    client
        .add_monitor(MonitorHttp {
            name: Some("Monitor Name".to_owned()),
            url: Some("https://example.com".to_owned()),
            parent: group.common().id().clone(),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_monitor".to_owned()),
                ..Default::default()
            }],
            notification_id_list: Some(
                vec![(
                    notification.id.expect("No notification ID").to_string(),
                    true,
                )]
                .into_iter()
                .collect(),
            ),
            ..Default::default()
        })
        .await
        .expect("Failed to add monitor");

    let monitors = client.get_monitors().await.expect("Failed to get monitors");
    println!("{:?}", monitors);
}
source

pub async fn get_monitor(&self, monitor_id: i32) -> Result<Monitor>

Retrieves information about a specific monitor identified by its ID.

source

pub async fn add_monitor<T: Into<Monitor>>(&self, monitor: T) -> Result<Monitor>

Adds a new monitor to Uptime Kuma.

Examples found in repository?
examples/create_monitor.rs (lines 32-40)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
async fn main() {
    // Connect to the server
    let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");

    // Create a tag
    let tag_definition = client
        .add_tag(TagDefinition {
            name: Some("example_tag".to_owned()),
            color: Some("red".to_owned()),
            ..Default::default()
        })
        .await
        .expect("Failed to add tag");

    // Create a group
    let group = client
        .add_monitor(MonitorGroup {
            name: Some("Example Group".to_owned()),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_group".to_owned()),
                ..Default::default()
            }],
            ..Default::default()
        })
        .await
        .expect("Failed to add group");

    // Createa a notification
    let notification = client
        .add_notification(Notification {
            name: Some("Example Notification".to_owned()),
            config: Some(serde_json::json!({
                "webhookURL": "https://webhook.site/304eeaf2-0248-49be-8985-2c86175520ca",
                "webhookContentType": "json"
            })),
            ..Default::default()
        })
        .await
        .expect("Failed to add notification");

    // Create a monitor
    client
        .add_monitor(MonitorHttp {
            name: Some("Monitor Name".to_owned()),
            url: Some("https://example.com".to_owned()),
            parent: group.common().id().clone(),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_monitor".to_owned()),
                ..Default::default()
            }],
            notification_id_list: Some(
                vec![(
                    notification.id.expect("No notification ID").to_string(),
                    true,
                )]
                .into_iter()
                .collect(),
            ),
            ..Default::default()
        })
        .await
        .expect("Failed to add monitor");

    let monitors = client.get_monitors().await.expect("Failed to get monitors");
    println!("{:?}", monitors);
}
source

pub async fn edit_monitor<T: Into<Monitor>>( &self, monitor: T ) -> Result<Monitor>

Edits an existing monitor in Uptime Kuma.

source

pub async fn delete_monitor(&self, monitor_id: i32) -> Result<()>

Deletes a monitor from Uptime Kuma based on its ID.

source

pub async fn pause_monitor(&self, monitor_id: i32) -> Result<()>

Pauses a monitor in Uptime Kuma based on its ID.

source

pub async fn resume_monitor(&self, monitor_id: i32) -> Result<()>

Resumes a paused monitor in Uptime Kuma based on its ID.

source

pub async fn get_tags(&self) -> Result<Vec<TagDefinition>>

Retrieves a list of tags from Uptime Kuma.

source

pub async fn get_tag(&self, tag_id: i32) -> Result<TagDefinition>

Retrieves information about a specific tag identified by its ID.

source

pub async fn add_tag(&self, tag: TagDefinition) -> Result<TagDefinition>

Adds a new tag to Uptime Kuma.

Examples found in repository?
examples/create_monitor.rs (lines 22-26)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
async fn main() {
    // Connect to the server
    let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");

    // Create a tag
    let tag_definition = client
        .add_tag(TagDefinition {
            name: Some("example_tag".to_owned()),
            color: Some("red".to_owned()),
            ..Default::default()
        })
        .await
        .expect("Failed to add tag");

    // Create a group
    let group = client
        .add_monitor(MonitorGroup {
            name: Some("Example Group".to_owned()),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_group".to_owned()),
                ..Default::default()
            }],
            ..Default::default()
        })
        .await
        .expect("Failed to add group");

    // Createa a notification
    let notification = client
        .add_notification(Notification {
            name: Some("Example Notification".to_owned()),
            config: Some(serde_json::json!({
                "webhookURL": "https://webhook.site/304eeaf2-0248-49be-8985-2c86175520ca",
                "webhookContentType": "json"
            })),
            ..Default::default()
        })
        .await
        .expect("Failed to add notification");

    // Create a monitor
    client
        .add_monitor(MonitorHttp {
            name: Some("Monitor Name".to_owned()),
            url: Some("https://example.com".to_owned()),
            parent: group.common().id().clone(),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_monitor".to_owned()),
                ..Default::default()
            }],
            notification_id_list: Some(
                vec![(
                    notification.id.expect("No notification ID").to_string(),
                    true,
                )]
                .into_iter()
                .collect(),
            ),
            ..Default::default()
        })
        .await
        .expect("Failed to add monitor");

    let monitors = client.get_monitors().await.expect("Failed to get monitors");
    println!("{:?}", monitors);
}
source

pub async fn edit_tag(&self, tag: TagDefinition) -> Result<TagDefinition>

Edits an existing tag in Uptime Kuma.

source

pub async fn delete_tag(&self, tag_id: i32) -> Result<()>

Deletes a tag from Uptime Kuma based on its ID.

source

pub async fn get_notifications(&self) -> Result<NotificationList>

Retrieves a list of notifications from Uptime Kuma.

source

pub async fn get_notification( &self, notification_id: i32 ) -> Result<Notification>

Retrieves information about a specific notification identified by its ID.

source

pub async fn add_notification( &self, notification: Notification ) -> Result<Notification>

Adds a new notification to Uptime Kuma.

Examples found in repository?
examples/create_monitor.rs (lines 46-53)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
async fn main() {
    // Connect to the server
    let client = Client::connect(Config {
        url: Url::parse("http://localhost:3001").expect("Invalid URL"),
        username: Some("Username".to_owned()),
        password: Some("Password".to_owned()),
        ..Default::default()
    })
    .await
    .expect("Failed to connect to server");

    // Create a tag
    let tag_definition = client
        .add_tag(TagDefinition {
            name: Some("example_tag".to_owned()),
            color: Some("red".to_owned()),
            ..Default::default()
        })
        .await
        .expect("Failed to add tag");

    // Create a group
    let group = client
        .add_monitor(MonitorGroup {
            name: Some("Example Group".to_owned()),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_group".to_owned()),
                ..Default::default()
            }],
            ..Default::default()
        })
        .await
        .expect("Failed to add group");

    // Createa a notification
    let notification = client
        .add_notification(Notification {
            name: Some("Example Notification".to_owned()),
            config: Some(serde_json::json!({
                "webhookURL": "https://webhook.site/304eeaf2-0248-49be-8985-2c86175520ca",
                "webhookContentType": "json"
            })),
            ..Default::default()
        })
        .await
        .expect("Failed to add notification");

    // Create a monitor
    client
        .add_monitor(MonitorHttp {
            name: Some("Monitor Name".to_owned()),
            url: Some("https://example.com".to_owned()),
            parent: group.common().id().clone(),
            tags: vec![Tag {
                tag_id: tag_definition.tag_id,
                value: Some("example_monitor".to_owned()),
                ..Default::default()
            }],
            notification_id_list: Some(
                vec![(
                    notification.id.expect("No notification ID").to_string(),
                    true,
                )]
                .into_iter()
                .collect(),
            ),
            ..Default::default()
        })
        .await
        .expect("Failed to add monitor");

    let monitors = client.get_monitors().await.expect("Failed to get monitors");
    println!("{:?}", monitors);
}
source

pub async fn edit_notification( &self, notification: Notification ) -> Result<Notification>

Edits an existing notification in Uptime Kuma.

source

pub async fn delete_notification(&self, notification_id: i32) -> Result<()>

Deletes a notification from Uptime Kuma based on its ID.

source

pub async fn get_maintenances(&self) -> Result<MaintenanceList>

Retrieves a list of maintenances from Uptime Kuma.

source

pub async fn get_maintenance(&self, maintenance_id: i32) -> Result<Maintenance>

Retrieves information about a specific maintenance identified by its ID.

source

pub async fn add_maintenance( &self, maintenance: Maintenance ) -> Result<Maintenance>

Adds a new maintenance to Uptime Kuma.

source

pub async fn edit_maintenance( &self, maintenance: Maintenance ) -> Result<Maintenance>

Edits an existing maintenance in Uptime Kuma.

source

pub async fn delete_maintenance(&self, maintenance_id: i32) -> Result<()>

Deletes a maintenance from Uptime Kuma based on its ID.

source

pub async fn pause_maintenance(&self, maintenance_id: i32) -> Result<()>

Pauses a maintenance in Uptime Kuma based on its ID.

source

pub async fn resume_maintenance(&self, maintenance_id: i32) -> Result<()>

Resumes a paused maintenance in Uptime Kuma based on its ID.

source

pub async fn get_status_pages(&self) -> Result<StatusPageList>

Retrieves a list of status pages from Uptime Kuma.

source

pub async fn get_status_page(&self, slug: &str) -> Result<StatusPage>

Retrieves information about a specific status page identified by its slug.

source

pub async fn add_status_page( &self, status_page: StatusPage ) -> Result<StatusPage>

Adds a new status page to Uptime Kuma.

source

pub async fn edit_status_page( &self, status_page: StatusPage ) -> Result<StatusPage>

Edits an existing status page in Uptime Kuma.

source

pub async fn delete_status_page(&self, slug: &str) -> Result<()>

Deletes a status page from Uptime Kuma based on its slug.

source

pub async fn get_docker_hosts(&self) -> Result<DockerHostList>

Retrieves a list of status pages from Uptime Kuma.

source

pub async fn get_docker_host(&self, docker_host_id: i32) -> Result<DockerHost>

Retrieves information about a specific docker host identified by its id.

source

pub async fn add_docker_host( &self, docker_host: DockerHost ) -> Result<DockerHost>

Adds a new docker host to Uptime Kuma.

source

pub async fn edit_docker_host( &self, docker_host: DockerHost ) -> Result<DockerHost>

Edits an existing docker host in Uptime Kuma.

source

pub async fn delete_docker_host(&self, docker_host_id: i32) -> Result<()>

Deletes a docker host from Uptime Kuma based on its id.

source

pub async fn test_docker_host(&self, docker_host: &DockerHost) -> Result<String>

Test a docker host in Uptime Kuma.

source

pub async fn disconnect(&self) -> Result<()>

Disconnects the client from Uptime Kuma.

Trait Implementations§

source§

impl Drop for Client

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more