diff --git a/rust-plugins/examples/tcpcon.json b/rust-plugins/examples/tcpcon.json new file mode 100644 index 0000000000..1e2778ebc6 --- /dev/null +++ b/rust-plugins/examples/tcpcon.json @@ -0,0 +1,42 @@ +{ + "collect": { + "snmp": [ + { + "name": "tcpConnectionState", + "oid": "1.3.6.1.2.1.6.19.1.7", + "query": "Walk" + }, + { + "name": "tcpListenerProcess", + "oid": "1.3.6.1.2.1.6.20.1.4", + "query": "Walk" + }, + { + "name": "tcpConnState", + "oid": "1.3.6.1.2.1.6.13.1.1", + "query": "Walk" + } + ] + }, + "compute": { + "metrics": [ + { + "name": "tcp.connections", + "value": "Average({tcpConnectionState})", + "uom": "", + "min": 0, + "threshold-suffix": "tcp-connections" + } + ] + }, + "output": { + "ok": "TCP connections are OK", + "detail_ok": false, + "warning": "TCP connections WARNING: ", + "detail_warning": true, + "critical": "TCP connections CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " + } +} diff --git a/rust-plugins/examples/udpcon.json b/rust-plugins/examples/udpcon.json new file mode 100644 index 0000000000..a72133e742 --- /dev/null +++ b/rust-plugins/examples/udpcon.json @@ -0,0 +1,31 @@ +{ + "collect": { + "snmp": [ + { + "name": "udpLocalAddress", + "oid": "1.3.6.1.2.1.7.7.1.8", + "query": "Walk" + } + ] + }, + "compute": { + "metrics": [ + { + "name": "udp.connections.ipv4", + "value": "({udpLocalAddress})", + "uom": "", + "min": 0 + } + ] + }, + "output": { + "ok": "UDP connections are OK", + "detail_ok": false, + "warning": "UDP connections WARNING: ", + "detail_warning": true, + "critical": "UDP connections CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " + } +} diff --git a/rust-plugins/src/compute/ast.rs b/rust-plugins/src/compute/ast.rs index b3946d7cdc..49d4ea263c 100644 --- a/rust-plugins/src/compute/ast.rs +++ b/rust-plugins/src/compute/ast.rs @@ -1,7 +1,7 @@ //! Abstract syntax tree and expression evaluation. use crate::snmp::SnmpResult; -use log::{info, warn}; +use log::{info, trace, warn}; use std::str; /// An expression node in the AST. @@ -280,6 +280,7 @@ impl ExprResult { /// the numbers to strings before concatenation, padding to match lengths /// where necessary. pub fn join(&mut self, other: &ExprResult) { + trace!("[join] self: {:?} - other: {:?}", &self, &other); match self { ExprResult::Empty => match other { ExprResult::StrVector(vv) => { @@ -289,7 +290,9 @@ impl ExprResult { *self = ExprResult::Str(s.clone()); } ExprResult::Vector(vv) => { - *self = ExprResult::StrVector(vv.iter().map(|n| crate::output::float_string(n)).collect()); + *self = ExprResult::StrVector( + vv.iter().map(|n| crate::output::float_string(n)).collect(), + ); } _ => panic!("Unable to join objects others than strings"), }, @@ -344,7 +347,8 @@ impl ExprResult { *s = format!("{}{}", s, ss); } ExprResult::Number(n) => { - *s = format!("{}{:.2}", s, crate::output::float_string(n)); + trace!("[join] n: {:?}", &n); + *s = format!("{}{}", s, crate::output::float_string(n)); } _ => panic!("Unable to join objects others than strings"), }, @@ -369,8 +373,10 @@ impl<'input> Expr<'input> { Err(format!("Undefined macro in expression: {{{}}}", k)) } Expr::Number(_) => Ok(()), - Expr::OpPlus(left, right) | Expr::OpMinus(left, right) | - Expr::OpStar(left, right) | Expr::OpSlash(left, right) => { + Expr::OpPlus(left, right) + | Expr::OpMinus(left, right) + | Expr::OpStar(left, right) + | Expr::OpSlash(left, right) => { left.validate_macros(collect)?; right.validate_macros(collect)?; Ok(()) diff --git a/rust-plugins/src/compute/mod.rs b/rust-plugins/src/compute/mod.rs index f30a0b8074..f16fb524f9 100644 --- a/rust-plugins/src/compute/mod.rs +++ b/rust-plugins/src/compute/mod.rs @@ -12,7 +12,7 @@ use self::ast::ExprResult; use self::lexer::{LexicalError, Tok}; use crate::snmp::SnmpResult; use lalrpop_util::{ParseError, lalrpop_mod}; -use log::debug; +use log::{debug, trace}; use regex::Regex; use serde::Deserialize; @@ -71,7 +71,7 @@ pub struct Compute { pub struct Parser<'a> { collect: &'a Vec, parser: grammar::ExprParser, - check_format: bool + check_format: bool, } impl<'a> Parser<'a> { @@ -80,7 +80,7 @@ impl<'a> Parser<'a> { Parser { collect, parser: grammar::ExprParser::new(), - check_format + check_format, } } @@ -88,10 +88,7 @@ impl<'a> Parser<'a> { /// /// Supports arithmetic operations, identifiers in braces (e.g., `{metric_name}`), /// and functions like `Average()`, `Min()`, `Max()`. - pub fn eval( - &self, - expr: &'a str, - ) -> Result { + pub fn eval(&self, expr: &'a str) -> Result { debug!("Parsing expression: {}", expr); let lexer = lexer::Lexer::new(expr); let res = self.parser.parse(lexer); @@ -110,13 +107,11 @@ impl<'a> Parser<'a> { /// /// Replaces `{identifier}` with values from SNMP results, handling both /// scalar and vector values appropriately. - pub fn eval_str( - &self, - expr: &'a str, - ) -> Result { + pub fn eval_str(&self, expr: &'a str) -> Result { let re = Regex::new(r"\{[a-zA-Z_][a-zA-Z0-9_.]*\}").unwrap(); let mut suffix = expr; let mut result: ExprResult = ExprResult::Empty; + trace!("[eval_str] suffix: {:?} - re: {:?}", &suffix, &re); loop { let found = re.find(suffix); if let Some(m) = found { diff --git a/rust-plugins/src/generic/mod.rs b/rust-plugins/src/generic/mod.rs index 7e1c6b0ff8..1488abf1b8 100644 --- a/rust-plugins/src/generic/mod.rs +++ b/rust-plugins/src/generic/mod.rs @@ -234,15 +234,20 @@ impl Command { target: &str, version: &str, community: &str, - check_format: bool + check_format: bool, ) -> Vec { let mut collect: Vec = Vec::new(); if check_format { - // In check-format mode, don't make SNMP requests and initialize with dummy values + // In check-format mode, don't make SNMP requests and initialize with dummy values. + // Get queries return a single value; Walk queries return multiple values. for s in self.collect.snmp.iter() { let mut items = HashMap::new(); - items.insert(s.name.clone(), ExprResult::Vector(vec![0.0, 0.0])); + let dummy = match s.query { + QueryType::Get => ExprResult::Vector(vec![0.0]), + QueryType::Walk => ExprResult::Vector(vec![0.0, 0.0]), + }; + items.insert(s.name.clone(), dummy); if let Some(lab) = &s.labels { for label_val in lab.values() { let key = format!("{}.{}", s.name, label_val); @@ -302,7 +307,7 @@ impl Command { community: &str, filter_in: &Vec, filter_out: &Vec, - check_format: bool + check_format: bool, ) -> Result { let mut collect = self.execute_snmp_collect(target, version, community, check_format); @@ -328,21 +333,25 @@ impl Command { let value = &metric.value; let parser = Parser::new(&collect, check_format); let value = parser.eval(value).map_err(|e| error::Error::InvalidJSON { - message: format!("Metric \"{}\", field \"value\": {}", metric.name, e) + message: format!("Metric \"{}\", field \"value\": {}", metric.name, e), })?; let min = if let Some(min_expr) = metric.min_expr.as_ref() { - parser.eval(&min_expr).map_err(|e| error::Error::InvalidJSON { - message: format!("Metric \"{}\", field \"min_expr\": {}", metric.name, e) - })? + parser + .eval(&min_expr) + .map_err(|e| error::Error::InvalidJSON { + message: format!("Metric \"{}\", field \"min_expr\": {}", metric.name, e), + })? } else if let Some(min_value) = metric.min { ExprResult::Number(min_value) } else { ExprResult::Empty }; let max = if let Some(max_expr) = metric.max_expr.as_ref() { - parser.eval(&max_expr).map_err(|e| error::Error::InvalidJSON { - message: format!("Metric \"{}\", field \"max_expr\": {}", metric.name, e) - })? + parser + .eval(&max_expr) + .map_err(|e| error::Error::InvalidJSON { + message: format!("Metric \"{}\", field \"max_expr\": {}", metric.name, e), + })? } else if let Some(max_value) = metric.max { ExprResult::Number(max_value) } else { @@ -357,21 +366,25 @@ impl Command { match &value { ExprResult::Vector(v) => { let prefix_str = match &metric.prefix { - Some(prefix) => parser.eval_str(prefix).map_err(|e| error::Error::InvalidJSON { - message: format!("Metric \"{}\", field \"prefix\": {}", metric.name, e) - })?, + Some(prefix) => { + parser + .eval_str(prefix) + .map_err(|e| error::Error::InvalidJSON { + message: format!( + "Metric \"{}\", field \"prefix\": {}", + metric.name, e + ), + })? + } None => ExprResult::Empty, }; for (i, item) in v.iter().enumerate() { - let name = match &prefix_str { - ExprResult::StrVector(v) => { - format!("{:?}#{}", v[i], metric.name) - } - ExprResult::Str(s) => { - format!("{}#{}", s, metric.name) - } + // first, compose the instance name + let instance_name = match &prefix_str { + ExprResult::StrVector(v) => v[i].to_string(), + ExprResult::Str(s) => s.to_string(), ExprResult::Empty => { - let res = format!("{}#{}", idx, metric.name); + let res = idx.to_string(); idx += 1; res } @@ -379,16 +392,18 @@ impl Command { panic!("A label must be a string"); } }; - if !re_in.is_empty() { - if !re_in.iter().any(|re| re.is_match(&name)) { - continue; - } + // then apply filters exclusion and inclusion filters + if !re_out.is_empty() && re_out.iter().any(|re| re.is_match(&instance_name)) + { + continue; } - if !re_out.is_empty() { - if re_out.iter().any(|re| re.is_match(&name)) { - continue; - } + if (!re_in.is_empty() + && !re_in.iter().any(|re| re.is_match(&instance_name))) + { + continue; } + // and now concatenate to form the full perfdata + let name = format!("'{}#{}'", instance_name, metric.name); let current_status = compute_status(item, &metric.warning, &metric.critical)?; status = worst(status, current_status); @@ -417,7 +432,7 @@ impl Command { ExprResult::Number(s) => { let name = match &metric.prefix { Some(prefix) => { - format!("{:?}#{}", prefix, metric.name) + format!("{}#{}", prefix, metric.name) } None => { let res = format!("{}#{}", idx, metric.name); @@ -472,9 +487,14 @@ impl Command { let value = &metric.value; let parser = Parser::new(&collect, check_format); let max = if let Some(max_expr) = metric.max_expr.as_ref() { - let res = parser.eval(&max_expr).map_err(|e| error::Error::InvalidJSON { - message: format!("Aggregation \"{}\", field \"max_expr\": {}", metric.name, e) - })?; + let res = parser + .eval(&max_expr) + .map_err(|e| error::Error::InvalidJSON { + message: format!( + "Aggregation \"{}\", field \"max_expr\": {}", + metric.name, e + ), + })?; Some(match res { ExprResult::Number(v) => v, ExprResult::Vector(v) => { @@ -489,9 +509,14 @@ impl Command { None }; let min = if let Some(min_expr) = metric.min_expr.as_ref() { - let res = parser.eval(&min_expr).map_err(|e| error::Error::InvalidJSON { - message: format!("Aggregation \"{}\", field \"min_expr\": {}", metric.name, e) - })?; + let res = parser + .eval(&min_expr) + .map_err(|e| error::Error::InvalidJSON { + message: format!( + "Aggregation \"{}\", field \"min_expr\": {}", + metric.name, e + ), + })?; Some(match res { ExprResult::Number(v) => v, ExprResult::Vector(v) => { @@ -506,7 +531,7 @@ impl Command { None }; let value = parser.eval(value).map_err(|e| error::Error::InvalidJSON { - message: format!("Aggregation \"{}\", field \"value\": {}", metric.name, e) + message: format!("Aggregation \"{}\", field \"value\": {}", metric.name, e), })?; match &value { ExprResult::Vector(v) => { diff --git a/rust-plugins/src/output/mod.rs b/rust-plugins/src/output/mod.rs index dab712c8ef..15dde5e2a3 100644 --- a/rust-plugins/src/output/mod.rs +++ b/rust-plugins/src/output/mod.rs @@ -45,7 +45,7 @@ pub struct Output { } fn default_ok() -> String { - "OK: Everything is ok".to_string() + "OK: Everything is ok ".to_string() } fn default_warning() -> String { "WARNING: ".to_string() @@ -208,7 +208,12 @@ impl<'a> OutputFormatter<'a> { for m in self.metrics.iter() { if let Some(status) = m.status { if status.is_worse_than(self.status) { - v.push(std::format!("{} is {}{}", m.name, float_string(&m.value), m.uom)); + v.push(std::format!( + "{} is {}{}", + m.name, + float_string(&m.value), + m.uom + )); } } } diff --git a/rust-plugins/src/snmp/mod.rs b/rust-plugins/src/snmp/mod.rs index 48a72cae4c..1cc7c0e00d 100644 --- a/rust-plugins/src/snmp/mod.rs +++ b/rust-plugins/src/snmp/mod.rs @@ -620,7 +620,9 @@ impl SnmpResult { match value { rasn_smi::v2::ApplicationSyntax::Address(ip_address) => todo!(), rasn_smi::v2::ApplicationSyntax::Counter(counter) => todo!(), - rasn_smi::v2::ApplicationSyntax::Ticks(time_ticks) => todo!(), + rasn_smi::v2::ApplicationSyntax::Ticks(time_ticks) => { + typ = ValueType::Integer(time_ticks.0.into()); + } rasn_smi::v2::ApplicationSyntax::Arbitrary(opaque) => todo!(), rasn_smi::v2::ApplicationSyntax::BigCounter(counter64) => { typ = ValueType::Counter64(counter64.0); diff --git a/tests/os/linux/snmp/cpu.robot b/tests/os/linux/snmp/cpu.robot index 202982d5cf..0b4b336d26 100644 --- a/tests/os/linux/snmp/cpu.robot +++ b/tests/os/linux/snmp/cpu.robot @@ -34,33 +34,18 @@ cpu ${tc} ... expected_result ... -- ... 1 - ... --use-ucd='0' - ... OK: 1 CPU(s) average usage is 2.00 % - CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;;;0;100 - ... 2 - ... --warning-average - ... OK: 1 CPU(s) average usage is 2.00 % - CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;;;0;100 - ... 3 - ... --critical-average - ... OK: 1 CPU(s) average usage is 2.00 % - CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;;;0;100 - ... 4 - ... --warning-core - ... OK: 1 CPU(s) average usage is 2.00 % - CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;;;0;100 - ... 5 - ... --critical-core - ... OK: 1 CPU(s) average usage is 2.00 % - CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;;;0;100 - ... 6 ... ${EMPTY} ... OK: 1 CPU(s) average usage is 2.00 % - CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;;;0;100 - ... 7 + ... 2 ... --warning-average='0' ... WARNING: 1 CPU(s) average usage is 2.00 % | 'total_cpu_avg'=2.00%;0:0;;0;100 'cpu'=2.00%;;;0;100 - ... 8 + ... 3 ... --critical-average='0' ... CRITICAL: 1 CPU(s) average usage is 2.00 % | 'total_cpu_avg'=2.00%;;0:0;0;100 'cpu'=2.00%;;;0;100 - ... 9 + ... 4 ... --warning-core='0' ... WARNING: CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;0:0;;0;100 - ... 10 + ... 5 ... --critical-core='0' ... CRITICAL: CPU '0' usage : 2.00 % | 'total_cpu_avg'=2.00%;;;0;100 'cpu'=2.00%;;0:0;0;100 @@ -83,7 +68,7 @@ cgs-cpu ${tc} ... -- ... 1 ... ${EMPTY} - ... OK: Everything is ok | 0#core.cpu.usage.percent=2%;;;0;100 avg.cpu.usage.percent=2%;;;0;100 + ... OK: avg.cpu.usage.percent is 2% | 0#core.cpu.usage.percent=2%;;;0;100 avg.cpu.usage.percent=2%;;;0;100 ... 2 ... --warning-avg=0.1 ... WARNING: avg.cpu.usage.percent is 2% | 0#core.cpu.usage.percent=2%;;;0;100 avg.cpu.usage.percent=2%;0.1;;0;100 diff --git a/tests/os/linux/snmp/fixed_date.pm b/tests/os/linux/snmp/fixed_date.pm new file mode 100644 index 0000000000..8b2127e7ee --- /dev/null +++ b/tests/os/linux/snmp/fixed_date.pm @@ -0,0 +1,10 @@ +package fixed_date; + +# Copyright 2026-Present Centreon +# Always use the same fixed date to test certificate validity + +BEGIN { + *CORE::GLOBAL::time = sub { 1723538393 }; +} + +1 diff --git a/tests/os/linux/snmp/generic-snmp/cpu.json b/tests/os/linux/snmp/generic-snmp/cpu.json index ad29a9ead0..192212872e 100644 --- a/tests/os/linux/snmp/generic-snmp/cpu.json +++ b/tests/os/linux/snmp/generic-snmp/cpu.json @@ -2,9 +2,9 @@ "collect": { "snmp": [ { - "name": "cpu", + "name": "cpu", "oid": "1.3.6.1.2.1.25.3.3.1.2", - "query": "Walk" + "query": "Walk" } ] }, @@ -13,21 +13,31 @@ { "name": "core.cpu.usage.percent", "value": "{cpu}", - "uom": "%", - "min": 0, - "max": 100, - "threshold-suffix": "cpu" + "uom": "%", + "min": 0, + "max": 100, + "threshold-suffix": "cpu" } ], "aggregations": [ { "name": "avg.cpu.usage.percent", - "value": "Average({cpu})", - "uom": "%", - "min": 0, - "max": 100, - "threshold-suffix": "avg" + "value": "Average({cpu})", + "uom": "%", + "min": 0, + "max": 100, + "threshold-suffix": "avg" } ] + }, + "output": { + "ok": "OK: avg.cpu.usage.percent is {aggregations.avg.cpu.usage.percent}%", + "detail_ok": false, + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " } } diff --git a/tests/os/linux/snmp/generic-snmp/inodes.json b/tests/os/linux/snmp/generic-snmp/inodes.json new file mode 100644 index 0000000000..d4880a6781 --- /dev/null +++ b/tests/os/linux/snmp/generic-snmp/inodes.json @@ -0,0 +1,39 @@ +{ + "collect": { + "snmp": [ + { + "name": "inodes", + "oid": "1.3.6.1.4.1.2021.9.1", + "query": "Walk", + "labels": { + ".2": "path", + ".3": "device", + ".10": "percent_used" + } + } + ] + }, + "compute": { + "metrics": [ + { + "prefix": "{inodes.path}", + "name": "inodes.usage.percent", + "value": "{inodes.percent_used}", + "uom": "%", + "min": 0, + "max": 100, + "threshold-suffix": "inodes" + } + ] + }, + "output": { + "ok": "All inode partitions are OK", + "detail_ok": false, + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " + } +} diff --git a/tests/os/linux/snmp/generic-snmp/memory-64.json b/tests/os/linux/snmp/generic-snmp/memory-64.json new file mode 100644 index 0000000000..8d85bd6eca --- /dev/null +++ b/tests/os/linux/snmp/generic-snmp/memory-64.json @@ -0,0 +1,54 @@ +{ + "collect": { + "snmp": [ + { + "name": "memTotalReal", + "oid": ".1.3.6.1.4.1.2021.4.20.0", + "query": "Get" + }, + { + "name": "memAvailReal", + "oid": ".1.3.6.1.4.1.2021.4.21.0", + "query": "Get" + } + ] + }, + "compute": { + "metrics": [], + "aggregations": [ + { + "name": "memory.free.bytes", + "value": "{memAvailReal}", + "uom": "B", + "min": 0, + "max_expr": "{memTotalReal}", + "threshold-suffix": "memory-free-bytes" + }, + { + "name": "memory.usage.bytes", + "value": "{memTotalReal} - {memAvailReal}", + "uom": "B", + "min": 0, + "max_expr": "{memTotalReal}", + "threshold-suffix": "memory-bytes" + }, + { + "name": "memory.usage.percent", + "value": "100 * ({memTotalReal} - {memAvailReal}) / {memTotalReal}", + "uom": "%", + "min": 0, + "max": 100, + "threshold-suffix": "memory-prct" + } + ] + }, + "output": { + "ok": "OK: Memory Used: {aggregations.memory.usage.bytes}B - Free: {aggregations.memory.free.bytes} - Total: {memTotalReal}", + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " + } +} diff --git a/tests/os/linux/snmp/generic-snmp/memory.json b/tests/os/linux/snmp/generic-snmp/memory.json new file mode 100644 index 0000000000..7151117428 --- /dev/null +++ b/tests/os/linux/snmp/generic-snmp/memory.json @@ -0,0 +1,54 @@ +{ + "collect": { + "snmp": [ + { + "name": "memTotalReal", + "oid": ".1.3.6.1.4.1.2021.4.5.0", + "query": "Get" + }, + { + "name": "memAvailReal", + "oid": ".1.3.6.1.4.1.2021.4.6.0", + "query": "Get" + } + ] + }, + "compute": { + "metrics": [], + "aggregations": [ + { + "name": "memory.free.bytes", + "value": "{memAvailReal}", + "uom": "B", + "min": 0, + "max_expr": "{memTotalReal}", + "threshold-suffix": "memory-free-bytes" + }, + { + "name": "memory.usage.bytes", + "value": "{memTotalReal} - {memAvailReal}", + "uom": "B", + "min": 0, + "max_expr": "{memTotalReal}", + "threshold-suffix": "memory-bytes" + }, + { + "name": "memory.usage.percent", + "value": "100 * ({memTotalReal} - {memAvailReal}) / {memTotalReal}", + "uom": "%", + "min": 0, + "max": 100, + "threshold-suffix": "memory-prct" + } + ] + }, + "output": { + "ok": "OK: Memory Used: {aggregations.memory.usage.bytes}B - Free: {aggregations.memory.free.bytes} - Total: {memTotalReal}", + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " + } +} diff --git a/tests/os/linux/snmp/generic-snmp/processcount.json b/tests/os/linux/snmp/generic-snmp/processcount.json new file mode 100644 index 0000000000..daffcd9950 --- /dev/null +++ b/tests/os/linux/snmp/generic-snmp/processcount.json @@ -0,0 +1,58 @@ +{ + "collect": { + "snmp": [ + { + "name": "processes", + "oid": "1.3.6.1.2.1.25.4.2.1", + "query": "Walk", + "labels": { + ".2": "name", + ".4": "path", + ".5": "args", + ".7": "status" + } + }, + { + "name": "processMem", + "oid": "1.3.6.1.2.1.25.5.1.1.2", + "query": "Walk" + }, + { + "name": "processCPU", + "oid": "1.3.6.1.2.1.25.5.1.1.1", + "query": "Walk" + } + ] + }, + "compute": { + "metrics": [ + { + "prefix": "{processes.name}", + "name": "process.memory.bytes", + "value": "{processMem} * 1024", + "uom": "B", + "min": 0, + "threshold-suffix": "process-memory" + }, + { + "prefix": "{processes.name}", + "name": "process.cpu.percent", + "value": "{processCPU}", + "uom": "%", + "min": 0, + "max": 100, + "threshold-suffix": "process-cpu" + } + ] + }, + "output": { + "ok": "All processes are OK", + "detail_ok": false, + "warning": "Process WARNING: ", + "detail_warning": true, + "critical": "Process CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " + } +} diff --git a/tests/os/linux/snmp/generic-snmp/storage.json b/tests/os/linux/snmp/generic-snmp/storage.json new file mode 100644 index 0000000000..874f1220b0 --- /dev/null +++ b/tests/os/linux/snmp/generic-snmp/storage.json @@ -0,0 +1,52 @@ +{ + "collect": { + "snmp": [ + { + "name": "storage", + "oid": "1.3.6.1.2.1.25.2.3.1", + "query": "Walk", + "labels": { + ".2": "type", + ".3": "description", + ".4": "allocation_units", + ".5": "size", + ".6": "used" + } + } + ] + }, + "compute": { + "metrics": [ + { + "prefix": "{storage.description}", + "name": "storage.usage.bytes", + "value": "{storage.used} * {storage.allocation_units}", + "uom": "B", + "min": 0, + "max_expr": "{storage.size} * {storage.allocation_units}", + "threshold-suffix": "storage-bytes" + }, + { + "prefix": "{storage.description}", + "name": "storage.usage.percent", + "value": "100 * {storage.used} / {storage.size}", + "uom": "%", + "min": 0, + "max": 100, + "threshold-suffix": "storage-prct" + } + ], + "aggregations": [ + ] + }, + "output": { + "ok": "All storages are OK", + "detail_ok": false, + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " + } +} diff --git a/tests/os/linux/snmp/generic-snmp/swap-64.json b/tests/os/linux/snmp/generic-snmp/swap-64.json index c2843458ee..9d5d987f08 100644 --- a/tests/os/linux/snmp/generic-snmp/swap-64.json +++ b/tests/os/linux/snmp/generic-snmp/swap-64.json @@ -16,11 +16,20 @@ "compute": { "metrics": [], "aggregations": [ + { + "name": "swap.free.bytes", + "value": "{memAvailSwap}", + "uom": "B", + "min": 0, + "max_expr": "{memTotalSwap}", + "threshold-suffix": "swap-free-bytes" + }, { "name": "swap.usage.bytes", "value": "{memTotalSwap} - {memAvailSwap}", "uom": "B", "min": 0, + "max_expr": "{memTotalSwap}", "threshold-suffix": "swap-bytes" }, { @@ -32,5 +41,14 @@ "threshold-suffix": "swap-prct" } ] + }, + "output": { + "ok": "OK: Swap Used: {aggregations.swap.usage.bytes}B - Free: {aggregations.swap.free.bytes}B - Total: {memTotalSwap}B", + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " } } diff --git a/tests/os/linux/snmp/generic-snmp/swap.json b/tests/os/linux/snmp/generic-snmp/swap.json index 94ee213a02..8e46bae379 100644 --- a/tests/os/linux/snmp/generic-snmp/swap.json +++ b/tests/os/linux/snmp/generic-snmp/swap.json @@ -16,11 +16,20 @@ "compute": { "metrics": [], "aggregations": [ + { + "name": "swap.free.bytes", + "value": "{memAvailSwap}", + "uom": "B", + "min": 0, + "max_expr": "{memTotalSwap}", + "threshold-suffix": "swap-free-bytes" + }, { "name": "swap.usage.bytes", "value": "{memTotalSwap} - {memAvailSwap}", "uom": "B", "min": 0, + "max_expr": "{memTotalSwap}", "threshold-suffix": "swap-bytes" }, { @@ -32,5 +41,14 @@ "threshold-suffix": "swap-prct" } ] + }, + "output": { + "ok": "OK: Swap Used: {aggregations.swap.usage.bytes}B - Free: {aggregations.swap.free.bytes}B - Total: {memTotalSwap}B", + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true, + "instance_separator": " - ", + "metric_separator": ", " } } diff --git a/tests/os/linux/snmp/generic-snmp/uptime.json b/tests/os/linux/snmp/generic-snmp/uptime.json new file mode 100644 index 0000000000..34211906dd --- /dev/null +++ b/tests/os/linux/snmp/generic-snmp/uptime.json @@ -0,0 +1,30 @@ +{ + "collect": { + "snmp": [ + { + "name": "hrSystemUptime", + "oid": ".1.3.6.1.2.1.25.1.1.0", + "query": "Get" + } + ] + }, + "compute": { + "metrics": [], + "aggregations": [ + { + "name": "system.uptime.seconds", + "value": "{hrSystemUptime} / 100", + "uom": "s", + "min": 0, + "threshold-suffix": "seconds" + } + ] + }, + "output": { + "ok": "OK: Uptime: {aggregations.system.uptime.seconds}s", + "warning": "WARNING: ", + "detail_warning": true, + "critical": "CRITICAL: ", + "detail_critical": true + } +} diff --git a/tests/os/linux/snmp/inodes.robot b/tests/os/linux/snmp/inodes.robot index 8ae2e824de..053a6945f3 100644 --- a/tests/os/linux/snmp/inodes.robot +++ b/tests/os/linux/snmp/inodes.robot @@ -9,7 +9,8 @@ Test Timeout 120s *** Variables *** -${CMD} ${CENTREON_PLUGINS} --plugin=os::linux::snmp::plugin +${CMD} ${CENTREON_PLUGINS} --plugin=os::linux::snmp::plugin +${CGS_CMD} ${CENTREON_GENERIC_SNMP} *** Test Cases *** @@ -27,9 +28,54 @@ inodes ${tc} Ctn Run Command And Check Result As Strings ${command} ${expected_result} - Examples: tc extra_options expected_result -- - ... 1 --filter-path='' OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 - ... 2 --display-transform-src='dev' OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_//shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 - ... 3 --display-transform-dst='run' OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 - ... 4 --filter-device OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 - ... 5 --filter-path OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... --filter-path='' + ... OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 + ... 2 + ... --display-transform-src='dev' + ... OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_//shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 + ... 3 + ... --display-transform-dst='run' + ... OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 + ... 4 + ... --filter-device + ... OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 + ... 5 + ... --filter-path + ... OK: All inode partitions are ok | 'used_/'=6%;;;0;100 'used_/dev/shm'=0%;;;0;100 'used_/run'=0%;;;0;100 'used_/run/lock'=0%;;;0;100 'used_/run/user/0'=0%;;;0;100 + +cgs-inodes ${tc} + [Tags] os linux centreon-generic-snmp + ${command} Catenate + ... ${CGS_CMD} + ... -j ${CURDIR}/generic-snmp/inodes.json + ... --hostname=${HOSTNAME} + ... --port=${SNMPPORT} + ... --snmp-version=${SNMPVERSION} + ... --snmp-community=os/linux/snmp/linux + ... ${extra_options} + + Ctn Run Command Without Connector And Check Result As Strings ${command} ${expected_result} + + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... ${EMPTY} + ... All inode partitions are OK | '/run#inodes.usage.percent'=0%;;;0;100 '/#inodes.usage.percent'=6%;;;0;100 '/dev/shm#inodes.usage.percent'=0%;;;0;100 '/run/lock#inodes.usage.percent'=0%;;;0;100 '/run/user/0#inodes.usage.percent'=0%;;;0;100 + ... 2 + ... --check-format + ... Check format of JSON file '${CURDIR}/generic-snmp/inodes.json' JSON is valid + ... 3 + ... --warning-inodes=1 + ... WARNING: '/#inodes.usage.percent' is 6% | '/run#inodes.usage.percent'=0%;1;;0;100 '/#inodes.usage.percent'=6%;1;;0;100 '/dev/shm#inodes.usage.percent'=0%;1;;0;100 '/run/lock#inodes.usage.percent'=0%;1;;0;100 '/run/user/0#inodes.usage.percent'=0%;1;;0;100 + ... 4 + ... --critical-inodes=1 + ... CRITICAL: '/#inodes.usage.percent' is 6% | '/run#inodes.usage.percent'=0%;;1;0;100 '/#inodes.usage.percent'=6%;;1;0;100 '/dev/shm#inodes.usage.percent'=0%;;1;0;100 '/run/lock#inodes.usage.percent'=0%;;1;0;100 '/run/user/0#inodes.usage.percent'=0%;;1;0;100 diff --git a/tests/os/linux/snmp/memory.robot b/tests/os/linux/snmp/memory.robot index 83aa357165..4f5c6650ff 100644 --- a/tests/os/linux/snmp/memory.robot +++ b/tests/os/linux/snmp/memory.robot @@ -9,7 +9,8 @@ Test Timeout 120s *** Variables *** -${CMD} ${CENTREON_PLUGINS} --plugin=os::linux::snmp::plugin +${CMD} ${CENTREON_PLUGINS} --plugin=os::linux::snmp::plugin +${CGS_CMD} ${CENTREON_GENERIC_SNMP} *** Test Cases *** @@ -199,3 +200,89 @@ memory ${tc} ... 2c ... --patch-redhat='1' ... OK: Ram Total: 5.91 TB Used (-buffers/cache): 5.89 TB (99.68%) Free: 19.12 GB (0.32%), Buffer: 694.54 MB, Cached: 219.41 GB, Shared: 9.31 GB | 'used'=6472685486080B;;;0;6493217484800 'free'=20531998720B;;;0;6493217484800 'used_prct'=99.68%;;;0;100 'buffer'=728276992B;;;0; 'cached'=235591376896B;;;0; 'shared'=9997410304B;;;0; + +cgs-mem ${tc} + [Tags] os linux centreon-generic-snmp + ${command} Catenate + ... ${CGS_CMD} + ... -j ${CURDIR}/generic-snmp/memory.json + ... --hostname=${HOSTNAME} + ... --port=${SNMPPORT} + ... --snmp-version=${SNMPVERSION} + ... --snmp-community=os/linux/snmp/linux + ... ${extra_options} + + Ctn Run Command Without Connector And Check Result As Strings ${command} ${expected_result} + + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... ${EMPTY} + ... OK: Memory Used: 1266544B - Free: 747712 - Total: 2014256 | memory.free.bytes=747712B;;;0;2014256 memory.usage.bytes=1266544B;;;0;2014256 memory.usage.percent=62.88%;;;0;100 + ... 2 + ... --warning-memory-bytes=0.1 + ... WARNING: memory.usage.bytes is 1266544B | memory.free.bytes=747712B;;;0;2014256 memory.usage.bytes=1266544B;0.1;;0;2014256 memory.usage.percent=62.88%;;;0;100 + ... 3 + ... --critical-memory-bytes=0.1 + ... CRITICAL: memory.usage.bytes is 1266544B | memory.free.bytes=747712B;;;0;2014256 memory.usage.bytes=1266544B;;0.1;0;2014256 memory.usage.percent=62.88%;;;0;100 + ... 4 + ... --warning-memory-prct=0.1 + ... WARNING: memory.usage.percent is 62.88% | memory.free.bytes=747712B;;;0;2014256 memory.usage.bytes=1266544B;;;0;2014256 memory.usage.percent=62.88%;0.1;;0;100 + ... 5 + ... --critical-memory-prct=0.1 + ... CRITICAL: memory.usage.percent is 62.88% | memory.free.bytes=747712B;;;0;2014256 memory.usage.bytes=1266544B;;;0;2014256 memory.usage.percent=62.88%;;0.1;0;100 + ... 6 + ... --check-format + ... Check format of JSON file '${CURDIR}/generic-snmp/memory.json' JSON is valid + ... 7 + ... --warning-memory-free-bytes=1 + ... WARNING: memory.free.bytes is 747712B | memory.free.bytes=747712B;1;;0;2014256 memory.usage.bytes=1266544B;;;0;2014256 memory.usage.percent=62.88%;;;0;100 + ... 8 + ... --critical-memory-free-bytes=1 + ... CRITICAL: memory.free.bytes is 747712B | memory.free.bytes=747712B;;1;0;2014256 memory.usage.bytes=1266544B;;;0;2014256 memory.usage.percent=62.88%;;;0;100 + +cgs-mem-64 ${tc} + [Tags] os linux centreon-generic-snmp + ${command} Catenate + ... ${CGS_CMD} + ... -j ${CURDIR}/generic-snmp/memory-64.json + ... --hostname=${HOSTNAME} + ... --port=${SNMPPORT} + ... --snmp-version=${SNMPVERSION} + ... --snmp-community=os/linux/snmp/linux + ... ${extra_options} + + Ctn Run Command Without Connector And Check Result As Strings ${command} ${expected_result} + + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... ${EMPTY} + ... OK: Memory Used: 6320981920B - Free: 20050780 - Total: 6341032700 | memory.free.bytes=20050780B;;;0;6341032700 memory.usage.bytes=6320981920B;;;0;6341032700 memory.usage.percent=99.68%;;;0;100 + ... 2 + ... --warning-memory-bytes=0.1 + ... WARNING: memory.usage.bytes is 6320981920B | memory.free.bytes=20050780B;;;0;6341032700 memory.usage.bytes=6320981920B;0.1;;0;6341032700 memory.usage.percent=99.68%;;;0;100 + ... 3 + ... --critical-memory-bytes=0.1 + ... CRITICAL: memory.usage.bytes is 6320981920B | memory.free.bytes=20050780B;;;0;6341032700 memory.usage.bytes=6320981920B;;0.1;0;6341032700 memory.usage.percent=99.68%;;;0;100 + ... 4 + ... --warning-memory-prct=0.1 + ... WARNING: memory.usage.percent is 99.68% | memory.free.bytes=20050780B;;;0;6341032700 memory.usage.bytes=6320981920B;;;0;6341032700 memory.usage.percent=99.68%;0.1;;0;100 + ... 5 + ... --critical-memory-prct=0.1 + ... CRITICAL: memory.usage.percent is 99.68% | memory.free.bytes=20050780B;;;0;6341032700 memory.usage.bytes=6320981920B;;;0;6341032700 memory.usage.percent=99.68%;;0.1;0;100 + ... 6 + ... --check-format + ... Check format of JSON file '${CURDIR}/generic-snmp/memory-64.json' JSON is valid + ... 7 + ... --warning-memory-free-bytes=1 + ... WARNING: memory.free.bytes is 20050780B | memory.free.bytes=20050780B;1;;0;6341032700 memory.usage.bytes=6320981920B;;;0;6341032700 memory.usage.percent=99.68%;;;0;100 + ... 8 + ... --critical-memory-free-bytes=1 + ... CRITICAL: memory.free.bytes is 20050780B | memory.free.bytes=20050780B;;1;0;6341032700 memory.usage.bytes=6320981920B;;;0;6341032700 memory.usage.percent=99.68%;;;0;100 diff --git a/tests/os/linux/snmp/processcount.robot b/tests/os/linux/snmp/processcount.robot index b2ad7743d0..5487699880 100644 --- a/tests/os/linux/snmp/processcount.robot +++ b/tests/os/linux/snmp/processcount.robot @@ -27,10 +27,49 @@ processcount ${tc} Ctn Run Command And Check Result As Strings ${command} ${expected_result} - Examples: tc extra_options expected_result -- - ... 1 --critical-cpu-total OK: Number of current processes running: 84 | 'nbproc'=84;;;0; - ... 2 --top OK: Number of current processes running: 84 | 'nbproc'=84;;;0; 'top_gorgone-proxy'=324349952B;;;0; 'top_Anonymized 068'=298323968B;;;0; 'top_Anonymized 148'=127754240B;;;0; 'top_Anonymized 054'=79663104B;;;0; 'top_gorgone-autodis'=72368128B;;;0; - ... 3 --top-num OK: Number of current processes running: 84 | 'nbproc'=84;;;0; - ... 4 --top-size OK: Number of current processes running: 84 | 'nbproc'=84;;;0; - ... 5 --process-status='running|runnable|unHandle' OK: Number of current processes running: 86 | 'nbproc'=86;;;0; - ... 6 --process-status='unHandled#-2' --process-name='Anonymized 228' --verbose OK: Number of current processes running: 1 | 'nbproc'=1;;;0; Process '3534' [name: Anonymized 228] [status: unHandled#-2] + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... --critical-cpu-total + ... OK: Number of current processes running: 84 | 'nbproc'=84;;;0; + ... 2 + ... --top + ... OK: Number of current processes running: 84 | 'nbproc'=84;;;0; 'top_gorgone-proxy'=324349952B;;;0; 'top_Anonymized 068'=298323968B;;;0; 'top_Anonymized 148'=127754240B;;;0; 'top_Anonymized 054'=79663104B;;;0; 'top_gorgone-autodis'=72368128B;;;0; + ... 3 + ... --top-num + ... OK: Number of current processes running: 84 | 'nbproc'=84;;;0; + ... 4 + ... --top-size + ... OK: Number of current processes running: 84 | 'nbproc'=84;;;0; + ... 5 + ... --process-status='running|runnable|unHandle' + ... OK: Number of current processes running: 86 | 'nbproc'=86;;;0; + ... 6 + ... --process-status='unHandled#-2' --process-name='Anonymized 228' --verbose + ... OK: Number of current processes running: 1 | 'nbproc'=1;;;0; Process '3534' [name: Anonymized 228] [status: unHandled#-2] + +cgs-processcount ${tc} + [Tags] os linux centreon-generic-snmp + ${command} Catenate + ... ${CENTREON_GENERIC_SNMP} + ... -j ${CURDIR}/generic-snmp/processcount.json + ... --hostname=${HOSTNAME} + ... --port=${SNMPPORT} + ... --snmp-version=${SNMPVERSION} + ... --snmp-community=os/linux/snmp/linux + ... --filter-in=111 + ... ${extra_options} + + Ctn Run Command Without Connector And Check Result As Strings ${command} ${expected_result} + + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... ${EMPTY} + ... All processes are OK | 'Anonymized 111#process.memory.bytes'=0B;;;0; 'Anonymized 111#process.cpu.percent'=0%;;;0;100 diff --git a/tests/os/linux/snmp/storage.robot b/tests/os/linux/snmp/storage.robot index 878c49f2a4..1d23eba035 100644 --- a/tests/os/linux/snmp/storage.robot +++ b/tests/os/linux/snmp/storage.robot @@ -27,9 +27,61 @@ storage ${tc} Ctn Run Command And Check Result As Strings ${command} ${expected_result} - Examples: tc extra_options expected_result -- - ... 1 --filter-duplicate='' OK: All storages are ok | 'count'=5;;;0; 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 - ... 2 --filter-storage-type='' OK: All storages are ok | 'count'=11;;;0; 'used_Physical memory'=1296941056B;;;0;2062598144 'used_Available memory'=0B;;;0;1143980032 'used_Virtual memory'=1296941056B;;;0;2062598144 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 'used_Memory buffers'=37601280B;;;0;2062598144 'used_Cached memory'=523030528B;;;0;523030528 'used_Shared memory'=30310400B;;;0;30310400 - ... 3 --display-transform-dst='run' OK: All storages are ok | 'count'=5;;;0; 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 - ... 4 --filter-duplicate OK: All storages are ok | 'count'=5;;;0; 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 - ... 5 --filter-storage-type OK: All storages are ok | 'count'=11;;;0; 'used_Physical memory'=1296941056B;;;0;2062598144 'used_Available memory'=0B;;;0;1143980032 'used_Virtual memory'=1296941056B;;;0;2062598144 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 'used_Memory buffers'=37601280B;;;0;2062598144 'used_Cached memory'=523030528B;;;0;523030528 'used_Shared memory'=30310400B;;;0;30310400 + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... --filter-duplicate='' + ... OK: All storages are ok | 'count'=5;;;0; 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 + ... 2 + ... --filter-storage-type='' + ... OK: All storages are ok | 'count'=11;;;0; 'used_Physical memory'=1296941056B;;;0;2062598144 'used_Available memory'=0B;;;0;1143980032 'used_Virtual memory'=1296941056B;;;0;2062598144 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 'used_Memory buffers'=37601280B;;;0;2062598144 'used_Cached memory'=523030528B;;;0;523030528 'used_Shared memory'=30310400B;;;0;30310400 + ... 3 + ... --display-transform-dst='run' + ... OK: All storages are ok | 'count'=5;;;0; 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 + ... 4 + ... --filter-duplicate + ... OK: All storages are ok | 'count'=5;;;0; 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 + ... 5 + ... --filter-storage-type + ... OK: All storages are ok | 'count'=11;;;0; 'used_Physical memory'=1296941056B;;;0;2062598144 'used_Available memory'=0B;;;0;1143980032 'used_Virtual memory'=1296941056B;;;0;2062598144 'used_/run'=532480B;;;0;206262272 'used_/'=7394013184B;;;0;105088212992 'used_/dev/shm'=0B;;;0;1031299072 'used_/run/lock'=0B;;;0;5242880 'used_/run/user/0'=0B;;;0;206258176 'used_Memory buffers'=37601280B;;;0;2062598144 'used_Cached memory'=523030528B;;;0;523030528 'used_Shared memory'=30310400B;;;0;30310400 + +cgs-storage ${tc} + [Tags] os linux centreon-generic-snmp + ${command} Catenate + ... ${CENTREON_GENERIC_SNMP} + ... -j ${CURDIR}/generic-snmp/storage.json + ... --hostname=${HOSTNAME} + ... --port=${SNMPPORT} + ... --snmp-version=${SNMPVERSION} + ... --snmp-community=os/linux/snmp/linux + ... --filter-out='([mM]emory|Swap)' + ... ${extra_options} + + Ctn Run Command Without Connector And Check Result As Strings ${command} ${expected_result} + + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... ${EMPTY} + ... All storages are OK | '/run#storage.usage.bytes'=532480B;;;0;206262272 '/#storage.usage.bytes'=7394013184B;;;0;105088212992 '/dev/shm#storage.usage.bytes'=0B;;;0;1031299072 '/run/lock#storage.usage.bytes'=0B;;;0;5242880 '/run/user/0#storage.usage.bytes'=0B;;;0;206258176 '/run#storage.usage.percent'=0.26%;;;0;100 '/#storage.usage.percent'=7.04%;;;0;100 '/dev/shm#storage.usage.percent'=0%;;;0;100 '/run/lock#storage.usage.percent'=0%;;;0;100 '/run/user/0#storage.usage.percent'=0%;;;0;100 + ... 2 + ... --filter-in='^\/$' + ... All storages are OK | '/#storage.usage.bytes'=7394013184B;;;0;105088212992 '/#storage.usage.percent'=7.04%;;;0;100 + ... 3 + ... --filter-in='^\/$' --warning-storage-bytes=1000 + ... WARNING: '/#storage.usage.bytes' is 7394013184B | '/#storage.usage.bytes'=7394013184B;1000;;0;105088212992 '/#storage.usage.percent'=7.04%;;;0;100 + ... 4 + ... --filter-in='^\/$' --critical-storage-bytes=1000 + ... CRITICAL: '/#storage.usage.bytes' is 7394013184B | '/#storage.usage.bytes'=7394013184B;;1000;0;105088212992 '/#storage.usage.percent'=7.04%;;;0;100 + ... 5 + ... --filter-in='^\/$' --warning-storage-prct=1 + ... WARNING: '/#storage.usage.percent' is 7.04% | '/#storage.usage.bytes'=7394013184B;;;0;105088212992 '/#storage.usage.percent'=7.04%;1;;0;100 + ... 6 + ... --filter-in='^\/$' --critical-storage-prct=1 + ... CRITICAL: '/#storage.usage.percent' is 7.04% | '/#storage.usage.bytes'=7394013184B;;;0;105088212992 '/#storage.usage.percent'=7.04%;;1;0;100 diff --git a/tests/os/linux/snmp/swap.robot b/tests/os/linux/snmp/swap.robot index 839f4ae814..bcb46f0a71 100644 --- a/tests/os/linux/snmp/swap.robot +++ b/tests/os/linux/snmp/swap.robot @@ -120,22 +120,28 @@ cgs-swap ${tc} ... -- ... 1 ... ${EMPTY} - ... OK: Everything is ok | swap.usage.bytes=499420B;;;0; swap.usage.percent=49.97%;;;0;100 + ... OK: Swap Used: 499420B - Free: 500000B - Total: 999420B | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;;0;100 ... 2 ... --warning-swap-bytes=0.1 - ... WARNING: swap.usage.bytes is 499420B | swap.usage.bytes=499420B;0.1;;0; swap.usage.percent=49.97%;;;0;100 + ... WARNING: swap.usage.bytes is 499420B | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;0.1;;0;999420 swap.usage.percent=49.97%;;;0;100 ... 3 ... --critical-swap-bytes=0.1 - ... CRITICAL: swap.usage.bytes is 499420B | swap.usage.bytes=499420B;;0.1;0; swap.usage.percent=49.97%;;;0;100 + ... CRITICAL: swap.usage.bytes is 499420B | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;0.1;0;999420 swap.usage.percent=49.97%;;;0;100 ... 4 ... --warning-swap-prct=0.1 - ... WARNING: swap.usage.percent is 49.97% | swap.usage.bytes=499420B;;;0; swap.usage.percent=49.97%;0.1;;0;100 + ... WARNING: swap.usage.percent is 49.97% | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;0.1;;0;100 ... 5 ... --critical-swap-prct=0.1 - ... CRITICAL: swap.usage.percent is 49.97% | swap.usage.bytes=499420B;;;0; swap.usage.percent=49.97%;;0.1;0;100 + ... CRITICAL: swap.usage.percent is 49.97% | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;0.1;0;100 ... 6 ... --check-format ... Check format of JSON file '${CURDIR}/generic-snmp/swap.json' JSON is valid + ... 7 + ... --warning-swap-free-bytes=1 + ... WARNING: swap.free.bytes is 500000B | swap.free.bytes=500000B;1;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;;0;100 + ... 8 + ... --critical-swap-free-bytes=1 + ... CRITICAL: swap.free.bytes is 500000B | swap.free.bytes=500000B;;1;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;;0;100 cgs-swap-64 ${tc} [Tags] os linux centreon-generic-snmp @@ -157,19 +163,25 @@ cgs-swap-64 ${tc} ... -- ... 1 ... ${EMPTY} - ... OK: Everything is ok | swap.usage.bytes=499420B;;;0; swap.usage.percent=49.97%;;;0;100 + ... OK: Swap Used: 499420B - Free: 500000B - Total: 999420B | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;;0;100 ... 2 ... --warning-swap-bytes=0.1 - ... WARNING: swap.usage.bytes is 499420B | swap.usage.bytes=499420B;0.1;;0; swap.usage.percent=49.97%;;;0;100 + ... WARNING: swap.usage.bytes is 499420B | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;0.1;;0;999420 swap.usage.percent=49.97%;;;0;100 ... 3 ... --critical-swap-bytes=0.1 - ... CRITICAL: swap.usage.bytes is 499420B | swap.usage.bytes=499420B;;0.1;0; swap.usage.percent=49.97%;;;0;100 + ... CRITICAL: swap.usage.bytes is 499420B | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;0.1;0;999420 swap.usage.percent=49.97%;;;0;100 ... 4 ... --warning-swap-prct=0.1 - ... WARNING: swap.usage.percent is 49.97% | swap.usage.bytes=499420B;;;0; swap.usage.percent=49.97%;0.1;;0;100 + ... WARNING: swap.usage.percent is 49.97% | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;0.1;;0;100 ... 5 ... --critical-swap-prct=0.1 - ... CRITICAL: swap.usage.percent is 49.97% | swap.usage.bytes=499420B;;;0; swap.usage.percent=49.97%;;0.1;0;100 + ... CRITICAL: swap.usage.percent is 49.97% | swap.free.bytes=500000B;;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;0.1;0;100 ... 6 ... --check-format - ... Check format of JSON file '${CURDIR}/generic-snmp/swap-64.json' JSON is valid \ No newline at end of file + ... Check format of JSON file '${CURDIR}/generic-snmp/swap-64.json' JSON is valid + ... 7 + ... --warning-swap-free-bytes=1 + ... WARNING: swap.free.bytes is 500000B | swap.free.bytes=500000B;1;;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;;0;100 + ... 8 + ... --critical-swap-free-bytes=1 + ... CRITICAL: swap.free.bytes is 500000B | swap.free.bytes=500000B;;1;0;999420 swap.usage.bytes=499420B;;;0;999420 swap.usage.percent=49.97%;;;0;100 diff --git a/tests/os/linux/snmp/time.robot b/tests/os/linux/snmp/time.robot index 0f99df2356..e834922692 100644 --- a/tests/os/linux/snmp/time.robot +++ b/tests/os/linux/snmp/time.robot @@ -1,5 +1,5 @@ *** Settings *** -Documentation Check time table +Documentation os::linux::snmp::plugin Resource ${CURDIR}${/}..${/}..${/}..${/}resources/import.resource @@ -9,29 +9,42 @@ Test Timeout 120s *** Variables *** -${CMD} ${CENTREON_PLUGINS} --plugin=os::linux::snmp::plugin +${INJECT_PERL} -Mfixed_date -I${CURDIR} +${CMD} ${CENTREON_PLUGINS} +... --plugin=os::linux::snmp::plugin +... --mode=time +... --hostname=${HOSTNAME} +... --snmp-port=${SNMPPORT} +... --snmp-community=os/linux/snmp/linux +${CGS_CMD} ${CENTREON_GENERIC_SNMP} *** Test Cases *** -time ${tc} - [Tags] os linux +time/ntp ${tc} + [Tags] os linux snmp ${command} Catenate ... ${CMD} - ... --mode=time - ... --hostname=${HOSTNAME} - ... --snmp-version=${SNMPVERSION} - ... --snmp-port=${SNMPPORT} - ... --snmp-community=os/linux/snmp/linux - ... --snmp-timeout=1 ... ${extra_options} - ${output} Run ${command} - ${output} Strip String ${output} - Should Match Regexp ${output} ${expected_result} - - Examples: tc extra_options expected_result -- - ... 1 --oid='' OK: Time offset (-?\\\\d+) second\\\\(s\\\\): Local Time : (\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}) \\\\(\\\\+\\\\d{4}\\\\) \\\\| 'offset'=(-?\\\\d+)s;.*$ - ... 2 --warning-offset='0' WARNING: Time offset (-?\\\\d+) second\\\\(s\\\\): Local Time : (\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}) \\\\(\\\\+\\\\d{4}\\\\) \\\\| 'offset'=(-?\\\\d+)s;.*$ - ... 3 --critical-offset='125' CRITICAL: Time offset (-?\\\\d+) second\\\\(s\\\\): Local Time : (\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}) \\\\(\\\\+\\\\d{4}\\\\) \\\\| 'offset'=(-?\\\\d+)s;.*$ - ... 4 --ntp-port=123 OK: Time offset (-?\\\\d+) second\\\\(s\\\\): Local Time : (\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}) \\\\(\\\\+\\\\d{4}\\\\) \\\\| 'offset'=(-?\\\\d+)s;.*$ - ... 5 --timezone='+0100' OK: Time offset (-?\\\\d+) second\\\\(s\\\\): Local Time : (\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}) \\\\(\\\\+\\\\d{4}\\\\) \\\\| 'offset'=(-?\\\\d+)s;.*$ + ${OLD_PERL5OPT} Get Environment Variable PERL5OPT default= + Set Environment Variable PERL5OPT ${INJECT_PERL} ${OLD_PERL5OPT} + + Ctn Run Command Without Connector And Check Result As Strings ${command} ${expected_result} + + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... ${EMPTY} + ... OK: Time offset -9 second(s): Local Time : 2024-08-13T10:39:44 (+0200) | 'offset'=-9s;;;; + ... 2 + ... --warning-offset=1 + ... WARNING: Time offset -9 second(s): Local Time : 2024-08-13T10:39:44 (+0200) | 'offset'=-9s;0:1;;; + ... 3 + ... --critical-offset=1 + ... CRITICAL: Time offset -9 second(s): Local Time : 2024-08-13T10:39:44 (+0200) | 'offset'=-9s;;0:1;; + ... 4 + ... --timezone='+0100' + ... OK: Time offset 3591 second(s): Local Time : 2024-08-13T10:39:44 (+0100) | 'offset'=3591s;;;; diff --git a/tests/os/linux/snmp/uptime.robot b/tests/os/linux/snmp/uptime.robot index 8cc5a58962..a5c4e5e80f 100644 --- a/tests/os/linux/snmp/uptime.robot +++ b/tests/os/linux/snmp/uptime.robot @@ -27,14 +27,42 @@ uptime ${tc} Ctn Run Command And Check Result As Strings ${command} ${expected_result} - Examples: tc extra_options expected_result -- - ... 1 --warning-uptime='2' WARNING: System uptime is: 38m 39s | 'uptime'=2319.00s;0:2;;0; - ... 2 --warning-uptime='1' WARNING: System uptime is: 38m 39s | 'uptime'=2319.00s;0:1;;0; - ... 3 --critical-uptime='2' CRITICAL: System uptime is: 38m 39s | 'uptime'=2319.00s;;0:2;0; - ... 4 --add-sysdesc OK: System uptime is: 38m 39s, Anonymized 023 | 'uptime'=2319.00s;;;0; - ... 5 --critical-uptime='1' CRITICAL: System uptime is: 38m 39s | 'uptime'=2319.00s;;0:1;0; - ... 6 --check-overload OK: System uptime is: 38m 39s | 'uptime'=2319.00s;;;0; - ... 7 --reboot-window OK: System uptime is: 38m 39s | 'uptime'=2319.00s;;;0; - ... 8 --unit='h' OK: System uptime is: 38m 39s | 'uptime'=0.64h;;;0; - ... 9 --unit='m' OK: System uptime is: 38m 39s | 'uptime'=38.65m;;;0; - ... 10 --unit='s' OK: System uptime is: 38m 39s | 'uptime'=2319.00s;;;0; + Examples: tc extra_options expected_result -- + ... 1 --warning-uptime='2' WARNING: System uptime is: 38m 39s | 'uptime'=2319.00s;0:2;;0; + ... 2 --warning-uptime='1' WARNING: System uptime is: 38m 39s | 'uptime'=2319.00s;0:1;;0; + ... 3 --critical-uptime='2' CRITICAL: System uptime is: 38m 39s | 'uptime'=2319.00s;;0:2;0; + ... 4 --add-sysdesc OK: System uptime is: 38m 39s, Anonymized 023 | 'uptime'=2319.00s;;;0; + ... 5 --critical-uptime='1' CRITICAL: System uptime is: 38m 39s | 'uptime'=2319.00s;;0:1;0; + ... 6 --check-overload OK: System uptime is: 38m 39s | 'uptime'=2319.00s;;;0; + ... 7 --reboot-window OK: System uptime is: 38m 39s | 'uptime'=2319.00s;;;0; + ... 8 --unit='h' OK: System uptime is: 38m 39s | 'uptime'=0.64h;;;0; + ... 9 --unit='m' OK: System uptime is: 38m 39s | 'uptime'=38.65m;;;0; + ... 10 --unit='s' OK: System uptime is: 38m 39s | 'uptime'=2319.00s;;;0; + +cgs-storage ${tc} + [Tags] os linux centreon-generic-snmp + ${command} Catenate + ... ${CENTREON_GENERIC_SNMP} + ... -j ${CURDIR}/generic-snmp/uptime.json + ... --hostname=${HOSTNAME} + ... --port=${SNMPPORT} + ... --snmp-version=${SNMPVERSION} + ... --snmp-community=os/linux/snmp/linux + ... ${extra_options} + + Ctn Run Command Without Connector And Check Result As Strings ${command} ${expected_result} + + Examples: + ... tc + ... extra_options + ... expected_result + ... -- + ... 1 + ... ${EMPTY} + ... OK: Uptime: 2319.87s | system.uptime.seconds=2319.87s;;;0; + ... 2 + ... --warning-seconds=1800 + ... WARNING: system.uptime.seconds is 2319.87s | system.uptime.seconds=2319.87s;1800;;0; + ... 3 + ... --critical-seconds=1800 + ... CRITICAL: system.uptime.seconds is 2319.87s | system.uptime.seconds=2319.87s;;1800;0;