Introducing SOC Insights for BloxOne Threat Defense: Boost your SOC efficiency with AI-driven insights to eliminate manual work and accelerate investigation and response times. Read the blog announcement here.

Automation Scripts

Reply

change script

Techie
Posts: 10
8372     0

Greeting

 

So Im newbie in script and infoblox,

I trying to make a script code.

My Q is :

when the 1st oct of ip address contain this numbers 192 or 193 and the bandwidth is the size of 4 megabytes

does two operations

first delete the data that old

It then executes the update command for which interface that have bandwidth 4096

 

Can any one  help me and audit my script ?

 

Script-Filter:
 $vendor eq "Cisco" and $sysdescr like /IOS/
########################################################################
Action:
 Config bandwidth
Action-Commands:
 SET: $updatemade = "no"
 sho run | in (^interface GigabitEthernet0/[0-2]|^ bandwidth|^ ip address [1-8][1-9]
 interface GigabitEthernet0/0
         bandwidth 4096
         ip address 172.16.235.110 255.255.255.252
        interface GigabitEthernet0/1
        interface GigabitEthernet0/2
         bandwidth 5120
        ip address 192.168.180.190 255.255.255.252
 
Output-Triggers:
Parse Output
########################################################################
Trigger:
 Parse Output
Trigger-Variables:
 $ipaddress string
        $banwidth string
        $number string
Trigger-Template:
        ip address [[$ipaddress]]
        bandwidth [[$banwidth]]
 interface GigabitEthernet 0/[[$number]]
Trigger-Commands: { $updatemade eq "no" and $ipaddress not in ["[1-8][1-9]","sif"] && $banwidth not in ["[4][0]",]}
config t
SET: $updatemade = "yes"
Trigger-Commands: { $updatemade eq "yes"and $banwidth not in ["????","???"]}
no policy-map PM_OUTPUT_Mobile
no policy-map PM_SHAPE_Mobile_OUT
no policy-map PM_INBOUND_Mobile
 
###########################################
Action:
 Add New bandwidth
Action-Commands:{ $updatemade eq "yes"}
 config t
 interface GigabitEthernet 0/[[$number]]
        bandwidth 5120
 end
 wr mem

 

Re: change script

Adviser
Posts: 65
8373     0

I left the policy map statements out as I don't see the relevance to a pure bandwidth swap.

 

You can find this script also in the infoblox-toolkit github: github/setbandwidth.ccs

Feel free to fork and improve!

 

 

########################################################################
## Export of Script: Change bandwidth on interface
## Script-Level: 3
## Script-Category: Uncategorized
## Script-Language: CCS
########################################################################
Script:
	Change bandwidth on interface

Script-Description:
	'Script to replace bandwidth from one value to another on interfaces and sub-interfaces that start with an octet.
    Old bandwidth, new bandwidth and octet(s) have to be provided at runtime'

Script-Filter:
    $Vendor eq "Cisco" and $sysDescr like /IOS/

Script-Variables:
	 $networktochange   ipaddress   "Replace bandwidth for interfaces and sub-interfaces that start with this octet"
	 $oldbandwidth      int         "Bandwidth value to look for (integer in kb)"
	 $newbandwidth      int         "Bandwidth value to replace the old one with (integer in kb)"

########################################################################
#   Check if interface is in network we want to change                 #
########################################################################

Action:
    ShowInterfaces

Action-Description:
    List interfaces and filter for the octet we want to limit the script to

Action-Commands:
    SET: $updatemade = "no"
    show ip int br | include $networktochange

Output-Triggers:
    Get Interfaces

########################################################################
#   Check if interface has BW value we want to replace                 #
########################################################################

Trigger:
    Get Interfaces

Trigger-Description:
    Trigger to parse out the interfaces from show ip int brief, extracts most types of interfaces and sub-interfaces.

Trigger-Variables:
    $IntName /\w+\d+(\/\d{1,2}|\/\d{1,2}\/\d+|\/\d{1,2}\.\d+|\/\d{1,2}\:\d+)?/

Trigger-Template:
    [[$IntName]]\s

Trigger-Commands:
    show interface $IntName | include ^_.MTU_.+_BW_$oldbandwidth

Output-Triggers:
    Parse Bandwidth

########################################################################
#   Check if interface has old BW value and update to new one          #
########################################################################

Trigger:
    Parse Bandwidth

Trigger-Description:
    Trigger to parse out the bandwidth from show interface, extracts bandwidth for evaluation

Trigger-Variables:
    $CurrentBandwidth int

Trigger-Template:
    BW\s[[$CurrentBandwidth]]\s

Trigger-Commands: {$updatemade eq "no"}
    SET: $updatemade = "yes"
    conf t
    interface $IntName
    bandwidth $newbandwidth
    EXPR: $counter = 1
    exit

Trigger-Commands: {$updatemade eq "yes"}
    interface $IntName
    bandwidth $newbandwidth
    EXPR: $counter = $counter + 1
    exit

########################################################################
#   Write the new config to memory                                     #
########################################################################

Action:
    Save Config if a change was made

Action-Commands: {$updatemade eq "no"}
    LOG-INFO: No Change was made

Action-Commands: {$updatemade eq "yes" and $counter eq 1}
    LOG-INFO: One interfaces has been updated
    PRINT: $counter interface has been updated
    end
    write memory

Action-Commands: {$updatemade eq "yes" and $counter > 1}
    LOG-INFO: Multiple interfaces have been updated
    PRINT: $counter interface have been updated
    end
    write memory

 

 

Re: change script

Techie
Posts: 10
8373     0

I appreciate your distinguished work. Thank you from my heart

Re: change script

Techie
Posts: 10
8373     0

error.PNG

 

hi ingmr,

 

This error happen with me a lot and i chaek everthing work fine 

 

and how he get interface 110 ??

Re: change script

Adviser
Posts: 65
8373     0

Can you provide the full output because this does not show where it grabs that value.

 

show ip int br | include $networktochange

 

This will show ip interface brief and filter out by the network you specify at the start.

 

It will then extract the intname for each line up to the first whitespace, your output for show ip int br | include $networktochange  must have returned a line that started with "100" followed by a whitespace.

 

The next command does not work because there is no such interface.

 

Re: change script

Techie
Posts: 10
8373     0

 

That I did was Delete the question mark
this cancel retry again
But I would like to know No. 11 where he came from, and how to fix it .

 

thankes.

 

########################################################################
## Export of Script: Change bandwidth on interface
## Script-Level: 3
## Script-Category: Uncategorized
## Script-Language: CCS
########################################################################


Script-Filter:
    $Vendor eq "Cisco" and $sysDescr like /IOS/

Script-Variables:
	 $networktochange   ipaddress   "Replace bandwidth for interfaces and sub-interfaces that start with this octet"
	 $oldbandwidth      int         "Bandwidth value to look for (integer in kb)"
	 $newbandwidth      int         "Bandwidth value to replace the old one with (integer in kb)"

########################################################################
#   Check if interface is in network we want to change                 #
########################################################################

Action:
    ShowInterfaces

Action-Description:
    List interfaces and filter for the octet we want to limit the script to

Action-Commands:
    SET: $updatemade = "no"
    show ip int br | include $networktochange

Output-Triggers:
    Get Interfaces

########################################################################
#   Check if interface has BW value we want to replace                 #
########################################################################

Trigger:
    Get Interfaces

Trigger-Description:
    Trigger to parse out the interfaces from show ip int brief, extracts most types of interfaces and sub-interfaces.

Trigger-Variables:
    $IntName /\w+\d+(\/\d{1,2}|\/\d{1,2}\/\d+|\/\d{1,2}\.\d+|\/\d{1,2}\:\d+)?/

Trigger-Template:
    [[$IntName]]\s

Trigger-Commands:
    show interface $IntName | include ^_.MTU_.+_BW_$oldbandwidth

Output-Triggers:
    Parse Bandwidth

########################################################################
#   Check if interface has old BW value and update to new one          #
########################################################################

Trigger:
    Parse Bandwidth

Trigger-Description:
    Trigger to parse out the bandwidth from show interface, extracts bandwidth for evaluation

Trigger-Variables:
    $CurrentBandwidth int

Trigger-Template:
    BW\s[[$CurrentBandwidth]]\s

Trigger-Commands: {$updatemade eq "no"}
    SET: $updatemade = "yes"
    conf t
    interface $IntName
    bandwidth $newbandwidth

    EXPR: $counter = 1
    exit

########################################################################
#   Write the new config to memory                                     #
########################################################################

Action:
    Save Config if a change was made

Action-Commands: {$updatemade eq "no"}
    LOG-INFO: No Change was made

Action-Commands: {$updatemade eq "yes" and $counter eq 1}
    LOG-INFO: One interfaces has been updated
    PRINT: $counter interface has been updated
    end
    write memory
 

 

 

Re: change script

Adviser
Posts: 65
8373     0

The 110 comes from the output of show ip int br | include $networktochange

 

This output gets parsed for $IntName

 

The Template for extraction is anything from that output up to the first whitespace

 

[[$IntName]]\s

 

And that matches the trigger variable: $IntName /\w+\d+(\/\d{1,2}|\/\d{1,2}\/\d+|\/\d{1,2}\.\d+|\/\d{1,2}\:\d+)?/

Some output from show ip int br | include $networktochange must have hade a newline that started with 110 and then a space.

 

Re: change script

Techie
Posts: 10
8373     0

Excellent explanation of the situation

Thank you so much Mr.ingmar

Showing results for 
Search instead for 
Did you mean: 

Recommended for You