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
impl Client
sourcepub async fn connect(config: Config) -> Result<Client>
pub async fn connect(config: Config) -> Result<Client>
Examples found in repository?
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
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);
}
sourcepub async fn get_monitors(&self) -> Result<MonitorList>
pub async fn get_monitors(&self) -> Result<MonitorList>
Retrieves a list of monitors from Uptime Kuma.
Examples found in repository?
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
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);
}
sourcepub async fn get_monitor(&self, monitor_id: i32) -> Result<Monitor>
pub async fn get_monitor(&self, monitor_id: i32) -> Result<Monitor>
Retrieves information about a specific monitor identified by its ID.
sourcepub async fn add_monitor<T: Into<Monitor>>(&self, monitor: T) -> Result<Monitor>
pub async fn add_monitor<T: Into<Monitor>>(&self, monitor: T) -> Result<Monitor>
Adds a new monitor to Uptime Kuma.
Examples found in repository?
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);
}
sourcepub async fn edit_monitor<T: Into<Monitor>>(
&self,
monitor: T
) -> Result<Monitor>
pub async fn edit_monitor<T: Into<Monitor>>( &self, monitor: T ) -> Result<Monitor>
Edits an existing monitor in Uptime Kuma.
sourcepub async fn delete_monitor(&self, monitor_id: i32) -> Result<()>
pub async fn delete_monitor(&self, monitor_id: i32) -> Result<()>
Deletes a monitor from Uptime Kuma based on its ID.
sourcepub async fn pause_monitor(&self, monitor_id: i32) -> Result<()>
pub async fn pause_monitor(&self, monitor_id: i32) -> Result<()>
Pauses a monitor in Uptime Kuma based on its ID.
sourcepub async fn resume_monitor(&self, monitor_id: i32) -> Result<()>
pub async fn resume_monitor(&self, monitor_id: i32) -> Result<()>
Resumes a paused monitor in Uptime Kuma based on its ID.
Retrieves a list of tags from Uptime Kuma.
sourcepub async fn get_tag(&self, tag_id: i32) -> Result<TagDefinition>
pub async fn get_tag(&self, tag_id: i32) -> Result<TagDefinition>
Retrieves information about a specific tag identified by its ID.
sourcepub async fn add_tag(&self, tag: TagDefinition) -> Result<TagDefinition>
pub async fn add_tag(&self, tag: TagDefinition) -> Result<TagDefinition>
Adds a new tag to Uptime Kuma.
Examples found in repository?
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);
}
sourcepub async fn edit_tag(&self, tag: TagDefinition) -> Result<TagDefinition>
pub async fn edit_tag(&self, tag: TagDefinition) -> Result<TagDefinition>
Edits an existing tag in Uptime Kuma.
sourcepub async fn delete_tag(&self, tag_id: i32) -> Result<()>
pub async fn delete_tag(&self, tag_id: i32) -> Result<()>
Deletes a tag from Uptime Kuma based on its ID.
sourcepub async fn get_notifications(&self) -> Result<NotificationList>
pub async fn get_notifications(&self) -> Result<NotificationList>
Retrieves a list of notifications from Uptime Kuma.
sourcepub async fn get_notification(
&self,
notification_id: i32
) -> Result<Notification>
pub async fn get_notification( &self, notification_id: i32 ) -> Result<Notification>
Retrieves information about a specific notification identified by its ID.
sourcepub async fn add_notification(
&self,
notification: Notification
) -> Result<Notification>
pub async fn add_notification( &self, notification: Notification ) -> Result<Notification>
Adds a new notification to Uptime Kuma.
Examples found in repository?
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);
}
sourcepub async fn edit_notification(
&self,
notification: Notification
) -> Result<Notification>
pub async fn edit_notification( &self, notification: Notification ) -> Result<Notification>
Edits an existing notification in Uptime Kuma.
sourcepub async fn delete_notification(&self, notification_id: i32) -> Result<()>
pub async fn delete_notification(&self, notification_id: i32) -> Result<()>
Deletes a notification from Uptime Kuma based on its ID.
sourcepub async fn get_maintenances(&self) -> Result<MaintenanceList>
pub async fn get_maintenances(&self) -> Result<MaintenanceList>
Retrieves a list of maintenances from Uptime Kuma.
sourcepub async fn get_maintenance(&self, maintenance_id: i32) -> Result<Maintenance>
pub async fn get_maintenance(&self, maintenance_id: i32) -> Result<Maintenance>
Retrieves information about a specific maintenance identified by its ID.
sourcepub async fn add_maintenance(
&self,
maintenance: Maintenance
) -> Result<Maintenance>
pub async fn add_maintenance( &self, maintenance: Maintenance ) -> Result<Maintenance>
Adds a new maintenance to Uptime Kuma.
sourcepub async fn edit_maintenance(
&self,
maintenance: Maintenance
) -> Result<Maintenance>
pub async fn edit_maintenance( &self, maintenance: Maintenance ) -> Result<Maintenance>
Edits an existing maintenance in Uptime Kuma.
sourcepub async fn delete_maintenance(&self, maintenance_id: i32) -> Result<()>
pub async fn delete_maintenance(&self, maintenance_id: i32) -> Result<()>
Deletes a maintenance from Uptime Kuma based on its ID.
sourcepub async fn pause_maintenance(&self, maintenance_id: i32) -> Result<()>
pub async fn pause_maintenance(&self, maintenance_id: i32) -> Result<()>
Pauses a maintenance in Uptime Kuma based on its ID.
sourcepub async fn resume_maintenance(&self, maintenance_id: i32) -> Result<()>
pub async fn resume_maintenance(&self, maintenance_id: i32) -> Result<()>
Resumes a paused maintenance in Uptime Kuma based on its ID.
sourcepub async fn get_status_pages(&self) -> Result<StatusPageList>
pub async fn get_status_pages(&self) -> Result<StatusPageList>
Retrieves a list of status pages from Uptime Kuma.
sourcepub async fn get_status_page(&self, slug: &str) -> Result<StatusPage>
pub async fn get_status_page(&self, slug: &str) -> Result<StatusPage>
Retrieves information about a specific status page identified by its slug.
sourcepub async fn add_status_page(
&self,
status_page: StatusPage
) -> Result<StatusPage>
pub async fn add_status_page( &self, status_page: StatusPage ) -> Result<StatusPage>
Adds a new status page to Uptime Kuma.
sourcepub async fn edit_status_page(
&self,
status_page: StatusPage
) -> Result<StatusPage>
pub async fn edit_status_page( &self, status_page: StatusPage ) -> Result<StatusPage>
Edits an existing status page in Uptime Kuma.
sourcepub async fn delete_status_page(&self, slug: &str) -> Result<()>
pub async fn delete_status_page(&self, slug: &str) -> Result<()>
Deletes a status page from Uptime Kuma based on its slug.
sourcepub async fn get_docker_hosts(&self) -> Result<DockerHostList>
pub async fn get_docker_hosts(&self) -> Result<DockerHostList>
Retrieves a list of status pages from Uptime Kuma.
sourcepub async fn get_docker_host(&self, docker_host_id: i32) -> Result<DockerHost>
pub async fn get_docker_host(&self, docker_host_id: i32) -> Result<DockerHost>
Retrieves information about a specific docker host identified by its id.
sourcepub async fn add_docker_host(
&self,
docker_host: DockerHost
) -> Result<DockerHost>
pub async fn add_docker_host( &self, docker_host: DockerHost ) -> Result<DockerHost>
Adds a new docker host to Uptime Kuma.
sourcepub async fn edit_docker_host(
&self,
docker_host: DockerHost
) -> Result<DockerHost>
pub async fn edit_docker_host( &self, docker_host: DockerHost ) -> Result<DockerHost>
Edits an existing docker host in Uptime Kuma.
sourcepub async fn delete_docker_host(&self, docker_host_id: i32) -> Result<()>
pub async fn delete_docker_host(&self, docker_host_id: i32) -> Result<()>
Deletes a docker host from Uptime Kuma based on its id.
sourcepub async fn test_docker_host(&self, docker_host: &DockerHost) -> Result<String>
pub async fn test_docker_host(&self, docker_host: &DockerHost) -> Result<String>
Test a docker host in Uptime Kuma.
sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnects the client from Uptime Kuma.