VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Geting logs from multiple nodes (https://forums.vandyke.com/showthread.php?t=14114)

aqelmo 03-19-2020 07:39 PM

Geting logs from multiple nodes
 
Hi.

Scripting is not my field so I'm having issues with making a script.

This is the situation: I'm connected to the system and authorized. I want to connect to several RBSs and get alarms from them.

Basically I need to do this on for each node:

Code:

        crt.Screen.Send "amos nodeID" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "alt" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "q" & chr(13)

I know I should be able to load nodes from a host file and then iterate this over that list but the example scripts are way too complicated and when I try to change anything it all fails miserably. I know how to log to separate files but this part is way over my head.

Some help would be appreciated.

bgagnon 03-20-2020 07:26 AM

Hi aqelmo,

Version of SecureCRT?

Quote:

I'm connected to the system and authorized. I want to connect to several RBSs and get alarms from them.
So "system" is different than RBSs? Do you need to make the connection from system to the RBS?

Please list the *explicit* steps as to how you would accomplish the task manually.

aqelmo 03-21-2020 05:50 AM

Hi,

Unfortunately, I'm using a really old version, 6.1.4.
Apparently "it's working and you don't need a new one".

It's Ericsson system for managing radio base stations.

Literally what I need to do is:

amos node1 (connect to node node1)
al (list alarms)
q (disconnect)
amos node2
al
q
amos node3
al
q
.
.
.



I would also append to separate log files for each node, that I know how to do.

bgagnon 03-22-2020 12:58 PM

Hi aqelmo,

It is still not clear to me if you are connected to the nodes or need to connect in the script.

If already connected, it is fairly easy to iterate over the connected tabs with a For/Next loop:

Code:

Sub Main()
    Do
        ' Iterate through all tabs, running commands
        For i = 1 To crt.GetTabCount
            Set objTab = crt.GetTab(i)
            ' Run Commands and disconnect
        Next
    Loop
End Sub


aqelmo 03-24-2020 04:00 PM

Hi.

I'm initially connected to the management system (jump host?) and then within the same session connect, issue commands and disconnect from managed nodes.
If I record the session as a script it looks like this:

Code:

Sub Main
        crt.Screen.Send "amos 0001" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "al" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "q" & chr(13)
crt.Screen.WaitForString chr(126) & "]$ "
        crt.Screen.Send "amos 0002" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "al" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "q" & chr(13)
crt.Screen.WaitForString chr(126) & "]$ "
        crt.Screen.Send "amos 0003" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "al" & chr(13)
        crt.Screen.WaitForString "[0m> "
        crt.Screen.Send "q" & chr(13)
End Sub



Code:

Sub Main
        crt.Screen.Send "amos 0001" & chr(13) <- connect to node 0001
        crt.Screen.WaitForString "[0m> " <- node prompt
        crt.Screen.Send "al" & chr(13) <- send command
        crt.Screen.WaitForString "[0m> " <- node prompt
        crt.Screen.Send "q" & chr(13) <- send disconnect command
crt.Screen.WaitForString chr(126) & "]$ " <- management system prompt
        crt.Screen.Send "amos 0002" & chr(13)  <- connect to node 0002
        crt.Screen.WaitForString "[0m> "  <- node prompt
        crt.Screen.Send "al" & chr(13) <- send command
        crt.Screen.WaitForString "[0m> "  <- node prompt
        crt.Screen.Send "q" & chr(13) <- send disconnect command
crt.Screen.WaitForString chr(126) & "]$ " <- management system prompt
        crt.Screen.Send "amos 0003" & chr(13)  <- connect to node 0003
        crt.Screen.WaitForString "[0m> " <- node prompt
        crt.Screen.Send "al" & chr(13)  <- send command
        crt.Screen.WaitForString "[0m> "  <- node prompt
        crt.Screen.Send "q" & chr(13)  <- send disconnect command
End Sub

I was looking at RunCommandsOnMultipleHostsAndLogResults and JumpHost-HandleSecondaryHostConnectionAttempts but both are just too much code go get few things I need.

bgagnon 03-25-2020 07:18 AM

Hi aqelmo,

How do you know what that first send is going to be?

Is it always amos 0001, amos 0002, amos 0003?

If not, where do you get the data from? How do you know what node(s) you will connect to?

Because even in a script, you have to know how to determine what to send, if that makes sense. :)

If just the three …
Code:

For i = 1 to 3
    crt.Screen.WaitForString chr(126) & "]$ "
    crt.Screen.Send "amos 000" & i & chr(13)
    crt.Screen.WaitForString "[0m> "
    crt.Screen.Send "al" & chr(13)
    crt.Screen.WaitForString "[0m> "
    crt.Screen.Send "q" & chr(13)
Next


aqelmo 03-25-2020 12:23 PM

Hi.

There are a few hundred nodes. I can export the list of nodes and get a file with single node ID per line. That should be an OK format for import? Since the list of nodes changes over time, it would be best to have it separately and not hardcoded into the script.

bgagnon 03-25-2020 01:27 PM

Hi aquelmo,

So are all worked on at the same time?

Or could it be amos 0015 to amos 0102, for example, at any given time?

If so, you can prompt the user for which nodes they will be working on (assuming they all have the amos prefix). Or you could pass those as arguments to the script.

aqelmo 03-27-2020 09:08 AM

After a lot of try and error, I managed to hack something that does what I want to do.


stop logging my session

loop
connect to node
get alarms
append to log file for that node
quit
stop logging
end loop

start logging my normal session



Now I need to get it to populate hosts aray from a file, instead of hardcoding it.
But coffee 1st.


Code:

# $language = "VBScript"
# $interface = "1.0"

g_strLogFileTemplate = "C:\path\Log\NODEID.txt"
crt.Screen.Synchronous = True
vHosts = Array(_
    "0001",_
    "0002",_
    "0003")


nIndex = 0

        crt.Session.Log False
Do
    Do
                crt.Screen.Send "amos " & vHosts(nIndex) & chr(13)
                crt.Screen.WaitForString "[0m> "
                crt.Screen.Send "alt" & chr(13)
                crt.Session.LogFileName = Replace( _
            g_strLogFileTemplate, _
            "NODEID", _
            vHosts(nIndex))
                        crt.Session.Log True, True
                crt.Screen.WaitForString "[0m> "
                crt.Session.Log False
                crt.Screen.Send "q" & chr(13)
                crt.Screen.WaitForString chr(126) & "]$ "
                Exit Do
    Loop

    nIndex = nIndex + 1


    If nIndex > Ubound(vHosts) Then Exit Do

Loop
        crt.Session.LogFileName = "C:\path\logs\%Y.%M.%D - %S_ENM.log"
        crt.Session.Log True, True


bgagnon 03-27-2020 09:47 AM

Hi aqelmo,

Congrats on your progress!

The previously referenced script (RunCommandsOnMultipleHostsAndLogResults) illustrates reading from a file. I understand when users feel a script has "more than they need" but it can still be used to borrow the relevant pieces of code. :)

aqelmo 03-27-2020 09:56 AM

I'm looking at it atm.
That and scripting essentials pdf.


All times are GMT -6. The time now is 05:14 AM.