This query takes the rather limited show mlag config-sanity command from an arista switch and generates a violation if it does not match the output below.
switch#show mlag config-sanity
No global configuration inconsistencies found.
No per interface configuration inconsistencies found.
The query identifies each line of the output and then creates two variables globalConfig and interfaceConfig, interfaceConfig is identified by check if interface exists in the line.
I am only expecting two lines therefore both variables once set won’t be added to. Watch this space if this changes I will update the query.
As in my previous queries I have included the extract that is in my “Arista Library” into the query for simplicity.
Finally there maybe a better way to do this as I had some fun and games getting this one to work so any feedback is gratefully appreciated.
/**
* @intent Mlag Config Sanity Checks
* @description Using the Arista Library we will check the configuration Sanity, there are only two lines in
* this output. One for the global configuration, and then Interface configuration, if we do not see the
* standard output we will error the configuration.
*/
/* Example Output of command
switch#show mlag config-sanity
No global configuration inconsistencies found.
No per interface configuration inconsistencies found.
*/
//show mlag config-sanity
export mlagConfigCheck(device: Device) =
foreach command in device.outputs.commands
where command.commandText == "show mlag config-sanity"
let mlagResponse = command.response
let parsed = parseConfigBlocks(OS.UNKNOWN, mlagResponse)
let globalConfig = ""
let interfaceConfig = ""
foreach textOutput in parsed
//Tidy up line text for processing including converting to a string.
let line = toString(textOutput)
let line = replace(line,"{text:","")
let line = replace(line,"}","")
let interfacePresent = matches(line,"*interface*")//Does this line related to Interface configuration?
let globalConfig = if !interfacePresent //Ensure Interface is not present in the line.
then if globalConfig != ""
// If global config has been writted then it should be left as is as there are only 2 lines in the output
then globalConfig
else line //Write the globalConfig variable as the line of text.
else "" // Do nothing
let interfaceConfig = if interfacePresent //Ensure Interface is present
then if interfaceConfig != ""
// If global config has been writted then it should be left as is as there are only 2 lines in the output
then interfaceConfig
else line // Write interfaceConfig as the line of text.
else "" //Do nothing
let returnResult = {globalConfig,interfacePresent,interfaceConfig} //Build return response.
select(returnResult);
processGlobal(ConfigSanity) =
foreach item in ConfigSanity
let globalConfig = item.globalConfig
select(globalConfig);
processInterface(ConfigSanity) =
foreach item in ConfigSanity
let interface = item.interfaceConfig
select(interface);
foreach device in network.devices
where device.platform.os == OS.ARISTA_EOS
//Retrieve configuration Sanity result.
let ConfigSanity = mlagConfigCheck(device)
let deviceName = device.name
let globalConfig = processGlobal(ConfigSanity)
let globalConfig = toString(globalConfig)
let interfaceConfig = processInterface(ConfigSanity)
let interfaceConfig = toString(interfaceConfig)
let globalConfigOk = if matches(globalConfig,"*No global configuration inconsistencies found*") || matches(globalConfig,"*Command not applicable for inactive MLAG state*")
then true
else false
let interfaceConfigOk = if matches(interfaceConfig,"*No per interface configuration inconsistencies found.*") || interfaceConfig == "[]"
then true
else false
let violation = if !globalConfigOk || !interfaceConfigOk
then true
else if !globalConfigOk && !interfaceConfigOk //This is more a catch all than anything else.
then true
else false
let violationText = if !globalConfigOk && !interfaceConfigOk
then "Error: Issue with global and interface config, response for global was "+globalConfig+", and for interface config it was "+interfaceConfig
else if !globalConfigOk && interfaceConfigOk
then "Error: Issue with Global Config"+globalConfig
else if globalConfigOk && !interfaceConfigOk
then "Error: Issue with Interface Config "+interfaceConfig
else if globalConfigOk && matches(globalConfig,"*Command not applicable for inactive MLAG state*")
then "MLAG is not configured on this device"
else ""
//Tidy up text output for global and interface config.
let globalConfig = replace(globalConfig,"[","")
let globalConfig = replace(globalConfig,"]","")
let interfaceConfig = replace(interfaceConfig,"[, ","")
let interfaceConfig = replace(interfaceConfig,"]","")
select {
Name:deviceName,
violation:violation,
Reason:violationText,
globalConfigOk:globalConfigOk,
interfaceConfigOk:interfaceConfigOk,
globalConfig:globalConfig,
interfaceConfig:interfaceConfig,
}



