Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-11-2015, 11:57 AM
Caoimhin Caoimhin is offline
Registered User
 
Join Date: Aug 2014
Posts: 35
Scripting Firewall Sessions with Python

My current script is as follows:

Code:
def Main():

	for X in range (1, crt.GetTabCount() + 1):
		Start = crt.GetScriptTab()
		CurrentTab = crt.GetTab(X)
		CurrentScreen = CurrentTab.Screen
		CurrentTab.Activate()
                Tab.Session.LogFileName = "C:\Users\O3278\Documents\Logs\Firewall Information %M-%D.log"
		CurrentScreen.Send("\r")
		CurrentScreen.Send("more system:running-config\r")
		if CurrentScreen.WaitForString("<--- More --->") == True:
			CurrentScreen.Send(" ")
		
Main()
I've had to dumb down the script multiple times but essentially what I want it to do is to set the log file for every session to the same file. Next I want it to go through the tabs one by one. I send a carriage return initially because I've set my sessions to send a period every 5 minutes to prevent the session from timing out. After the line is cleared I send a command to the current tab waiting for "<---More--->" and sending a spacebar if it comes up.

I know this can be done because I've done it in VB. But what I'm encountering is the log file was being reset fine, but each session was trying to send the data at the same time. I was getting multiple copies of the file with a _1, _2, _3 appended to it. Now I've managed to get the script to cycle through the open tabs and send a CR in each tab. When I add the command to the script the command gets run multiple times in the script tab, but not in the other tabs.

I'm wondering if the primary session is being overwhelmed. I'm going to try it with a crt.Sleep(3000) and see if the command gets issues to the other tabs. Or it may be that I need to increase the "Line Send Delay".

Anyone have any ideas?
Reply With Quote
  #2  
Old 02-11-2015, 12:46 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Caoimhin,

Thanks for the post.

I see that you are getting a CurrentTab object, but then when you set the log, you don't use the CurrentTab object.

If you modify the line that logs to use CurrentTab, do you get better results?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 02-11-2015, 01:21 PM
Caoimhin Caoimhin is offline
Registered User
 
Join Date: Aug 2014
Posts: 35
Funny I was thinking the same thing. So the code was altered since my last post:

Code:
# $language = "python"
# $interface = "1.0"

def Main():

	for X in range (1, crt.GetTabCount() + 1):
		Start = crt.GetScriptTab()
		CurrentTab = crt.GetTab(X)
		CurrentScreen = CurrentTab.Screen
		CurrentTab.Activate()
		CurrentScreen.Synchronous == True
		CurrentTab.Session.LogFileName = "C:\Users\O3278\Documents\Logs\Firewall Information %M-%D.log"
		if not crt.Session.Logging == True:
			crt.Session.Logging (True, True)
		CurrentScreen.Send("\r")
		CurrentScreen.Send("more system:running-config\r")
		for Y in range (1, 20):
			CurrentScreen.Send(" ")
		crt.Sleep(10000)
		CurrentTab.Session.LogFileName = "C:\Users\O3278\Documents\Logs\Firewalls\%S %M-%D.log"
		
Main()
This script is now issuing the command to each tab and cycling through the <---More---> pauses. My log file is not being created though. I know the script changes the log file successfully. I have run the code separately and then checked the session details. I've been looking into alternative methods of streaming the data to a file.
Reply With Quote
  #4  
Old 02-11-2015, 01:32 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Caoimhin,

You are now using the crt object rather than the CurrentTab object to determine if logging is enabled.

Additionally, you are trying to set the Logging property which is read only. If you want to start logging, you would need to use the CurrentTab object and the Log() method.

Does this help to resolve the issue?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:33 PM.