cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

Site Engine Python Scripting - VOSS Enable SFLOW

Site Engine Python Scripting - VOSS Enable SFLOW

dreader
New Contributor II

I am trying to get used to scripting but have not found anything that does what i want.

I want to send CLI commands to groups but have the %deviceIP built in to the script so it make changes as i need.

For example i was to enable SFLOW so i need to have the local IP in this config.

config terminal
sflow agent-ip %deviceIP
sflow collector 1 address x.x.x.x owner DEV-SiteEngine port 6343 timeout 497
sflow collector 2 address x.x.x.x owner PRD-SiteEngine port 6343 timeout 497
app-telemetry enable

I was also trying to see if there is anyway to do pip install commands to get more features in the scripts.

1 ACCEPTED SOLUTION

Markus_Nikulski
Extreme Employee

first, in your CLI command bulk is missing the enable command on the leading position.

second, why do you send sFlow data to Site Engine? It should go to the Analytics Engine. And if you add the switch to the Analytics Engine he gets automatically configured with App Telemetry and not only sFlow, which is more advanced.

View solution in original post

6 REPLIES 6

dreader
New Contributor II

I've been trying to troubleshoot by adding regex as well but all i ever get is the same export from site engine.
Script Name: TEST-Gather-MGMT-Push-SFLOW
Date and Time: 2024-06-07T15:09:36.638
XIQ-SE User: root
XIQ-SE User Domain:
IP: 172.16.7.62

import re
from xmclib import emc_vars
from xmclib import cli

def configure_device():
device_ip = emc_vars["deviceIP"]
device_login = emc_vars["deviceLogin"]
device_pwd = emc_vars["devicePwd"]
cli_port = emc_vars.get("cliPort", 22) # Default to SSH port 22 if not specified

# Define the CLI commands
cli_commands = [
"conf t",
"sflow agent-ip {}".format(device_ip),
"sflow collector 1 address 172.16.52.46 owner DEV-SiteEngine port 6343 timeout 497",
"sflow collector 2 address 10.252.52.23 owner adcprdsiteengine01 port 6343 timeout 497",
"app-telemetry enable",
"exit", # Add 'exit' to commit changes if necessary
"save config" # Add 'save config' to ensure configuration is saved
]

try:
print("Connecting to device {}...".format(device_ip))

# Initialize the connection
session = cli.CliCommand(device_ip, user=device_login, password=device_pwd, port=cli_port)

# Execute each command individually and capture the output
for command in cli_commands:
print("Running command: {}".format(command))
result = session.execute(command)

if result:
print("Command output: {}".format(result))
print("Successfully executed command on device {}: {}".format(device_ip, command))
else:
print("Failed to execute command on device {}: {}".format(device_ip, command))
return

# Example of capturing and parsing the output for verification
verification_command = "show sflow configuration" # Replace with an appropriate verification command
print("Running verification command: {}".format(verification_command))
verification_result = session.execute(verification_command)

if verification_result:
print("Verification command output: {}".format(verification_result))

# Parse the output using regex
regex = re.compile(r"sflow agent-ip (\d+\.\d+\.\d+\.\d+)")
for line in verification_result.splitlines():
match = regex.search(line)
if match:
agent_ip = match.group(1)
print("Parsed sflow agent IP: {}".format(agent_ip))
else:
print("Failed to execute verification command on device {}".format(device_ip))

except Exception as ex:
print("Exception occurred while configuring device {}: {}".format(device_ip, str(ex)))

if __name__ == "__main__":
configure_device()

not sure where you got the inspiration for this Python script. If you are using Python inside Site Engine, the CLI handling is much simpler.

 

 

from xmcbase import cli as emc_cli
from xmcbase import emc_vars

###############################################################
def sendConfigCmds(cmdsšŸ˜ž
    for cmd in cmds:
        cli_results = emc_cli.send( cmd )
        if cli_results.isSuccess() is False:
            print('CLI-ERROR: ' + cli_results.getError())
            return False
           
    lines = cli_results.getOutput().splitlines()[1:-1]
    if lines:
        return lines
    else:
        return True

###############################################################
##                         MAIN                              ##
###############################################################
def main():
    cmds = '''
enable
configure
sflow agent-ip <DEVICE_IP>
sflow collector 1 address 172.16.52.46 owner DEV-SiteEngine port 6343 timeout 497
sflow collector 2 address 10.252.52.23 owner adcprdsiteengine01 port 6343 timeout 497
app-telemetry enable
exit
save config
'''
   
    cmds = cmds.replace('<DEVICE_IP>',emc_vars["deviceIP"])

    sendConfigCmds( cmds.splitlines() )

###############################################################

main()
GTM-P2G8KFN