-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AppError is essentially an ApiError. The idea is we can use "anyhow" everywhere with the exception of API handlers, as we want to turn those into specific errors codes like bad request, internal server error, not implemented, etc.
- Loading branch information
Showing
19 changed files
with
190 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// SPDX-FileCopyrightText: (C) 2020 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
use tracing::{debug, error, warn}; | ||
use crate::prelude::*; | ||
|
||
use crate::{ | ||
elastic::{AlertQueryOptions, ElasticResponse}, | ||
|
@@ -10,7 +10,6 @@ use crate::{ | |
}; | ||
|
||
use super::{ElasticEventRepo, MINIMUM_SHOULD_MATCH}; | ||
use crate::error::AppError; | ||
|
||
impl ElasticEventRepo { | ||
pub fn build_inbox_query(&self, options: AlertQueryOptions) -> serde_json::Value { | ||
|
@@ -161,14 +160,14 @@ impl ElasticEventRepo { | |
query | ||
} | ||
|
||
pub async fn alerts(&self, options: AlertQueryOptions) -> Result<AlertsResult, AppError> { | ||
pub async fn alerts(&self, options: AlertQueryOptions) -> Result<AlertsResult> { | ||
let mut query = self.build_inbox_query(options); | ||
query["timeout"] = "3s".into(); | ||
let start = std::time::Instant::now(); | ||
let body = self.search(&query).await?.text().await?; | ||
let response: ElasticResponse = serde_json::from_str(&body)?; | ||
if let Some(error) = &response.error { | ||
return Err(AppError::ElasticSearchError(error.first_reason())); | ||
bail!("elasticsearch: {}", error.first_reason()); | ||
} | ||
|
||
debug!( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// SPDX-FileCopyrightText: (C) 2023 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::prelude::*; | ||
|
||
use super::ElasticEventRepo; | ||
use crate::error::AppError; | ||
use crate::{ | ||
datetime::DateTime, | ||
elastic::request::{term_filter, timestamp_gte_filter}, | ||
|
@@ -14,7 +15,7 @@ impl ElasticEventRepo { | |
earliest: Option<DateTime>, | ||
dhcp_type: &str, | ||
sensor: Option<String>, | ||
) -> Result<Vec<serde_json::Value>, AppError> { | ||
) -> Result<Vec<serde_json::Value>> { | ||
let mut filters = vec![]; | ||
|
||
if let Some(earliest) = &earliest { | ||
|
@@ -67,15 +68,15 @@ impl ElasticEventRepo { | |
&self, | ||
earliest: Option<DateTime>, | ||
sensor: Option<String>, | ||
) -> Result<Vec<serde_json::Value>, AppError> { | ||
) -> Result<Vec<serde_json::Value>> { | ||
self.dhcp(earliest, "request", sensor).await | ||
} | ||
|
||
pub async fn dhcp_ack( | ||
&self, | ||
earliest: Option<DateTime>, | ||
sensor: Option<String>, | ||
) -> Result<Vec<serde_json::Value>, AppError> { | ||
) -> Result<Vec<serde_json::Value>> { | ||
self.dhcp(earliest, "ack", sensor).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
// SPDX-FileCopyrightText: (C) 2020 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::prelude::*; | ||
|
||
use super::ElasticEventRepo; | ||
use crate::elastic::request; | ||
use crate::error::AppError; | ||
use crate::eventrepo::{self}; | ||
use crate::LOG_QUERIES; | ||
use serde_json::json; | ||
use tracing::info; | ||
use tracing::warn; | ||
|
||
const MINIMUM_SHOULD_MATCH: &str = "minimum_should_match"; | ||
|
||
impl ElasticEventRepo { | ||
pub async fn events( | ||
&self, | ||
params: eventrepo::EventQueryParams, | ||
) -> Result<serde_json::Value, AppError> { | ||
pub async fn events(&self, params: eventrepo::EventQueryParams) -> Result<serde_json::Value> { | ||
let mut filters = vec![request::exists_filter(&self.map_field("event_type"))]; | ||
let mut should = vec![]; | ||
let mut must_not = vec![]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.