DataPower

 View Only
  • 1.  Script to SSH into a DataPower VM, create an error report, and download that error report locally.

    Posted 20 days ago
    I am attempting to create a script that will allow me to SSH into our DataPower VM, create an error report, and download that error report locally. To date, I am attempting to SSH into DataPower and issue the 'save error-report' command. Here is the script:
    ```
    # Import the SSH module
    Import-Module Posh-SSH
    # Define variables
    $hostname = "myDataPowerVM"
    $username = "me"
    $password = "PasswordHere"
    # Create an SSH session
    $session = New-SSHSession -ComputerName $hostname -Credential (New-Object -TypeName PSCredential -ArgumentList $username, (ConvertTo-SecureString -String $password -AsPlainText -Force))
    # Check if the session was created successfully
    if ($session.Connected) {
        # Run the command to create the error report
    $command = "sw myDomain; co; save error-report;"
    $output = Invoke-SSHCommand -SessionId $session.SessionId -Command $command 
    # Clean up the SSH session
    Remove-SSHSession -SessionId $session.SessionId
    } else {
        Write-Host "Failed to create SSH session. Please check your credentials and network connectivity."
    }
    ```
    The above returns the following error: Exception calling "EndExecute" with "1" argument(s): "Command 'sw myDomain; co; save error-report;' has timed out."
    Has anyone created a script (PowerShell, Bash, etc.) that creates and then downloads an error-report.txt file?


    ------------------------------
    EIS Developer
    ------------------------------


  • 2.  RE: Script to SSH into a DataPower VM, create an error report, and download that error report locally.

    Posted 20 days ago

    This is brute force technique I use in the lab.  It is not recommended because the login creds appear in the script.  There are solutions to that problem including the recommended ways using xml-mgmt or rest-mgmt.  That said, here's to going brutal!
    cat dp-run-cli.sh 

    #!/bin/bash

    # $1 is quoted string that is the DP CLI 
    # $2 is the filename containing the DP hosts on which you want to run the cli


    echo "dp-run-cli.sh utilization"
    echo './dp-run-cli.sh utilization "top;co;save error-report" [file with list of dp to run this cli, default filename is dplist]'


    INFILE=cli.txt

    if [[ $(echo $1 |grep -E 'write|no domain|shut') ]]; then
        ans=y
    else
          ans=""
    fi
    if [ -z "$2" ]
    then
       dplist="dplist"
    else
       dplist=$2    
    fi


    cat << EOF > $INFILE
    admin
    **password**
    default
    $1
    ${ans}
    EOF

    for DPHOST in $(cat ./${2}|sed 's/\r//g'); do
        cat $INFILE >$DPHOST.cli
        ssh  -T $DPHOST < $DPHOST.cli 2>&1 > $DPHOST.run-cli.txt &

    done



    ------------------------------
    Ivan Heninger
    ------------------------------



  • 3.  RE: Script to SSH into a DataPower VM, create an error report, and download that error report locally.

    Posted 20 days ago

    I'll add that the CLI you send can include things like "top;co;save error-report" for which the resulting error-report file name will be shown in the log file $DPHOST.run-cli.txt.  Then you can follow up with "top;co;copy -f temporary:///error-report.0000000.20240614182452359UTC.txt.gz scp://<user>:<pwd>@<host>//<path>/error-report.0000000.20240614182452359UTC.txt.gz"



    ------------------------------
    Ivan Heninger
    ------------------------------



  • 4.  RE: Script to SSH into a DataPower VM, create an error report, and download that error report locally.

    IBM Champion
    Posted 20 days ago

    Ahhhh, the exhausting work people do when they don't have to.   FWIW, you could pick up a copy of KumbaSoft's DPAA and do it against any arbitrary number of appliances in about three clicks of a mouse.  No typing.  No headaches.   And, you can view the error report data right in the tool, comparing error reports from different appliances at the same time, or error reports taken on the same appliance at different times, or even compare against error reports saved off the boxes or even sent to you.

    It also has a neat little checkbox allowing you to delete the error reports from the appliances once you've downloaded them from the boxes.

    The error reports are saved in a directory on your machine for sending to IBM or for comparing later.



    ------------------------------
    Joseph Morgan
    ------------------------------