(&self, kuma: &Client, id: &String, entity: &Entity)
| 33 | } |
| 34 | |
| 35 | async fn create_entity(&self, kuma: &Client, id: &String, entity: &Entity) -> Result<()> { |
| 36 | info!("Creating new {}: {}", entity.entity_type(), id); |
| 37 | match entity.clone() { |
| 38 | Entity::Monitor(monitor) => { |
| 39 | match kuma.add_monitor(monitor).await { |
| 40 | Ok(monitor) => { |
| 41 | let db_id = monitor.common().id().ok_or_else(|| { |
| 42 | KumaError::CommunicationError( |
| 43 | "Did not receive an id from Uptime Kuma".to_owned(), |
| 44 | ) |
| 45 | })?; |
| 46 | |
| 47 | self.app_state |
| 48 | .db |
| 49 | .store_id(Name::Monitor(id.clone()), db_id)?; |
| 50 | |
| 51 | Ok(()) |
| 52 | } |
| 53 | Err(err) => Err(err), |
| 54 | }?; |
| 55 | } |
| 56 | Entity::DockerHost(docker_host) => { |
| 57 | let db_id = kuma.add_docker_host(docker_host).await?.id.ok_or_else(|| { |
| 58 | KumaError::CommunicationError( |
| 59 | "Did not receive an id from Uptime Kuma".to_owned(), |
| 60 | ) |
| 61 | })?; |
| 62 | |
| 63 | self.app_state |
| 64 | .db |
| 65 | .store_id(Name::DockerHost(id.clone()), db_id)?; |
| 66 | } |
| 67 | Entity::Notification(notification) => { |
| 68 | let db_id = kuma |
| 69 | .add_notification(notification) |
| 70 | .await? |
| 71 | .id |
| 72 | .ok_or_else(|| { |
| 73 | KumaError::CommunicationError( |
| 74 | "Did not receive an id from Uptime Kuma".to_owned(), |
| 75 | ) |
| 76 | })?; |
| 77 | |
| 78 | self.app_state |
| 79 | .db |
| 80 | .store_id(Name::Notification(id.clone()), db_id)?; |
| 81 | } |
| 82 | Entity::StatusPage(status_page) => { |
| 83 | let db_id = kuma |
| 84 | .add_status_page(status_page) |
| 85 | .await? |
| 86 | .slug |
| 87 | .ok_or_else(|| { |
| 88 | KumaError::CommunicationError( |
| 89 | "Did not receive an id from Uptime Kuma".to_owned(), |
| 90 | ) |
| 91 | })?; |
| 92 |
no test coverage detected