-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from vulogov/0.9.0
0.9.0
- Loading branch information
Showing
15 changed files
with
630 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"clock": 1719081343, | ||
"ns": 515516610, | ||
"value": 1, | ||
"eventid": 51, | ||
"name": "SLA triggered", | ||
"severity": 4, | ||
"hosts": [ | ||
{ | ||
"host": "test_host", | ||
"name": "test_host" | ||
} | ||
], | ||
"groups": [ | ||
"Linux servers" | ||
], | ||
"tags": [ | ||
{ | ||
"tag": "SLA", | ||
"value": "TEST" | ||
} | ||
] | ||
} | ||
|
||
{"clock":1719081346,"ns":754691765,"value":0,"eventid":52,"p_eventid":51} |
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
extern crate log; | ||
use crate::cmd; | ||
use crate::stdlib; | ||
use std::str::FromStr; | ||
use std::path::Path; | ||
use zenoh::config::{Config, ConnectConfig, ListenConfig, EndPoint, WhatAmI}; | ||
|
||
pub fn run(c: &cmd::Cli, alerts: &cmd::Alerts) { | ||
log::debug!("zbus_alerts::run() reached"); | ||
|
||
let mut config = Config::default(); | ||
if alerts.zbus_disable_multicast_scout.clone() { | ||
match config.scouting.multicast.set_enabled(Some(false)) { | ||
Ok(_) => { log::debug!("Multicast discovery disabled")} | ||
Err(err) => { | ||
log::error!("Failure in disabling multicast discovery: {:?}", err); | ||
return; | ||
} | ||
} | ||
} else { | ||
log::debug!("Multicast discovery enabled"); | ||
} | ||
match EndPoint::from_str(&alerts.zbus_connect) { | ||
Ok(zconn) => { | ||
log::debug!("ZENOH bus set to: {:?}", &zconn); | ||
let _ = config.set_connect(ConnectConfig::new(vec![zconn]).unwrap()); | ||
} | ||
Err(err) => { | ||
log::error!("Failure in parsing connect address: {:?}", err); | ||
return; | ||
} | ||
} | ||
match EndPoint::from_str(&alerts.zbus_listen) { | ||
Ok(zlisten) => { | ||
log::debug!("ZENOH listen set to: {:?}", &zlisten); | ||
let _ = config.set_listen(ListenConfig::new(vec![zlisten]).unwrap()); | ||
} | ||
Err(_) => { | ||
log::debug!("ZENOH listen set to default"); | ||
} | ||
} | ||
if alerts.zbus_set_connect_mode { | ||
log::debug!("ZENOH configured in CONNECT mode"); | ||
let _ = config.set_mode(Some(WhatAmI::Client)); | ||
} else { | ||
log::debug!("ZENOH configured in PEER mode"); | ||
let _ = config.set_mode(Some(WhatAmI::Peer)); | ||
} | ||
if config.validate() { | ||
log::debug!("ZENOH config is OK"); | ||
} else { | ||
log::error!("ZENOH config not OK"); | ||
return; | ||
} | ||
|
||
match &alerts.script { | ||
Some(fname) => { | ||
if Path::new(&fname).exists() { | ||
log::debug!("Filtering and transformation enabled"); | ||
cmd::zbus_alerts_processor_filter::processor(c, alerts); | ||
cmd::zbus_alerts_processor_transformation::processor(c, alerts); | ||
} else { | ||
log::error!("Script not found processing disabled"); | ||
return; | ||
} | ||
} | ||
None => log::debug!("Filtering disabled"), | ||
} | ||
|
||
cmd::zbus_alerts_zabbix::catcher(c, alerts); | ||
cmd::zbus_alerts_processor::processor(c, alerts); | ||
cmd::zbus_thread_zbus_sender::sender(c, config, true, false, alerts.zbus_key.clone()); | ||
|
||
|
||
stdlib::threads::wait_all(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
extern crate log; | ||
use crate::cmd; | ||
use crate::stdlib; | ||
use serde_json::{json, Deserializer, Value}; | ||
|
||
pub fn processor(c: &cmd::Cli, alerts: &cmd::Alerts) { | ||
log::debug!("zbus_alerts_processor::run() reached"); | ||
let c = c.clone(); | ||
let alerts = alerts.clone(); | ||
match stdlib::threads::THREADS.lock() { | ||
Ok(t) => { | ||
t.execute(move || | ||
{ | ||
log::debug!("ALERTS PROCESSOR thread has been started"); | ||
loop { | ||
if ! stdlib::channel::pipe_is_empty_raw("in".to_string()) { | ||
match stdlib::channel::pipe_pull("in".to_string()) { | ||
Ok(res) => { | ||
log::debug!("Received {} bytes by processor", &res.len()); | ||
let stream = Deserializer::from_str(&res).into_iter::<Value>(); | ||
for value in stream { | ||
match value { | ||
Ok(zjson) => { | ||
if ! zjson.is_object() { | ||
log::error!("Received JSON is not an object: {}", &zjson); | ||
continue; | ||
} | ||
let value = match cmd::zbus_gateway_processor::zabbix_json_get_raw(&zjson, "value".to_string()) { | ||
Some(value) => value, | ||
None => continue, | ||
}; | ||
if ! value.is_i64() { | ||
log::error!("Alert value is not an integer"); | ||
continue; | ||
} | ||
let ivalue = match value.as_i64() { | ||
Some(ivalue) => ivalue, | ||
None => continue, | ||
}; | ||
let id = match ivalue { | ||
0 => { | ||
match stdlib::alerts::resolve_alert(zjson.clone()) { | ||
Some(id) => id, | ||
None => continue, | ||
} | ||
} | ||
1 => { | ||
log::debug!("Adding alert"); | ||
match stdlib::alerts::add_alert(zjson.clone()) { | ||
Some(id) => id, | ||
None => continue, | ||
} | ||
} | ||
_ => continue, | ||
}; | ||
log::trace!("Alertid: {:?} {:?}", &id, &zjson); | ||
let data = json!({ | ||
"headers": { | ||
"messageType": "event", | ||
"route": c.route.clone(), | ||
"streamName": c.platform_name.clone(), | ||
"cultureCode": null, | ||
"version": c.protocol_version.clone(), | ||
"encryptionAlgorithm": null, | ||
"compressionAlgorithm": null, | ||
}, | ||
"body": { | ||
"details": { | ||
"origin": alerts.source.clone(), | ||
"destination": format!("/{}", alerts.zbus_key), | ||
"properties": { | ||
"zabbix_clock": cmd::zbus_gateway_processor::zabbix_json_get(&zjson, "clock".to_string()), | ||
"zabbix_ns": cmd::zbus_gateway_processor::zabbix_json_get(&zjson, "ns".to_string()), | ||
"zabbix_host_name": cmd::zbus_gateway_processor::zabbix_json_get(&zjson, "hosts".to_string()), | ||
"zabbix_eventid": cmd::zbus_gateway_processor::zabbix_json_get(&zjson, "eventid".to_string()), | ||
"name": cmd::zbus_gateway_processor::zabbix_json_get(&zjson, "name".to_string()), | ||
"tags": cmd::zbus_gateway_processor::zabbix_json_get(&zjson, "tags".to_string()), | ||
"groups": cmd::zbus_gateway_processor::zabbix_json_get(&zjson, "groups".to_string()), | ||
}, | ||
"details": { | ||
"detailType": "", | ||
"contentType": 3, | ||
"data": value, | ||
} | ||
} | ||
}, | ||
"id": id, | ||
}); | ||
match &alerts.script { | ||
Some(_) => { | ||
stdlib::channel::pipe_push("filter".to_string(), data.to_string()); | ||
} | ||
None => { | ||
|
||
stdlib::channel::pipe_push("out".to_string(), data.to_string()); | ||
} | ||
} | ||
} | ||
Err(err) => { | ||
log::error!("Error converting JSON: {:?}", err); | ||
} | ||
} | ||
} | ||
} | ||
Err(err) => log::error!("Error getting data from channel: {:?}", err), | ||
} | ||
} else { | ||
stdlib::sleep::sleep(1); | ||
} | ||
} | ||
}); | ||
drop(t); | ||
} | ||
Err(err) => { | ||
log::error!("Error accessing Thread Manager: {:?}", err); | ||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.