Skip to main content

As part of doing configuration audits for our NX-OS devices, I needed a check to see if two conditions were met in a configuration to check compliance.

If both conditions were present → Good
If one condition was met and the other wasn’t → BAD
Else if → Both conditions were not present → Also good.

This is relatively simple with a single condition, but adding another variable, kind of stumped me. 
Credit to Glen Turner @FN for solving the logic puzzle on this.

The example below is for OSPF enabled and SNMP traps for OSPF is enabled. This logic can be used for many other two condition checks such as 

//Vars
PatternNetFlow = ```
feature netflow
```;

PatternNetFlow_Config = ```
flow timeout active 60
```;

//Functions
CheckPattern(config , pattern) = !hasBlockMatch(config, pattern);

&&

 

//Vars
PatternBFD = ```
feature bfd
```;

PatternBFD_Config = ```
bfd interval 300 min_rx 300 multiplier 3
```;

//Functions
CheckPattern(config , pattern) = !hasBlockMatch(config, pattern);

 

/**
* @intent Ensure DC NX-OS Devices have SNMP for OSPF enabled.
* @description 5/18/2024 - If OSPF feature is enabled, then SNMP-SERVER enable traps needs to be enabled. If Feature is not enabled, then SNMP-Server enable traps shouldn't be enabled.
*/


//Vars
PatternOSPF = ```
feature ospf
```;

PatternSnmp = ```
snmp-server enable traps ospf
```;

//Functions
CheckPattern(config , pattern) = !hasBlockMatch(config, pattern);


//Main
foreach device in network.devices
let platform = device.platform
// only look at devices with tagNames in "Quotes"
where "NX-OS" in device.tagNames
//&& "Core" in device.tagNames && "C9500" in device.tagNames
// Thank you Glen T.
let ospfCheck = CheckPattern(device.files.config , PatternOSPF)
let snmpCheck = CheckPattern(device.files.config , PatternSnmp)
let truthTable = ospfCheck && snmpCheck

let status =
if truthTable == false
then if ospfCheck == false && snmpCheck == false
then "Config Good"
else if ospfCheck == false && snmpCheck == true
then "OSPF Enabled, SNMP Missing"
else "SNMP MISSING"
else "No OSPF = Config Good"


select {
deviceName: device.name,
ip:device.platform.managementIps,
"Missing OSPF Feature (True=Yes)": ospfCheck,
"Missing SNMP (True=Yes)": snmpCheck,
Status: status,
platform: platform.os,
model:platform.model,
tag:device.tagNames
}

Here are a few examples of the results , above. 

So basically

anything that is FALSE/FALSE = Feature is Enabled and SNMP is configured → GOOD 
anything that is FALSE/TRUE = Feature is enabled, but SNMP isn’t configured → BAD
anything that is TRUE/TRUE = Feature not enabled, and SNMP for OSPF shouldn’t exist → GOOD

Be the first to reply!

Reply