Welcome to Netcordia Connection Sign in | Join | Help
in Search

Add SNMP Community String

Last post 05-15-2008 9:43 AM by mgriffin. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-14-2008 2:51 PM

    Add SNMP Community String

    Script:
        Add SNMP community String

    Script-Description:
        This script adds an SNMP community string to a cisco switch or router,
        if SNMP is enabled.
       
    Script-Filter:
        $Vendor eq "Cisco"
        and $Type in ["Switch", "Switch-Router", "Router"]
        and $sysDescr like /IOS/

    Script-Variables:
        $NewCommunityString    string
        $RW            boolean
       
    ########################################################################
    Action:
        Confirm SNMP

    Action-Description:
        Make sure SNMP is enabled on the device

    Action-Commands:
        SET: $snmpEnabled = "true"
        show snmp
       
    Output-Triggers:
        Determine SNMP Status
        SNMP Disabled
        Determine RW String
        Add Community String
       
    ########################################################################
    Trigger:
        Determine SNMP Status

    Trigger-Description:
        Determine whether SNMP is enabled or disabled
       
    Trigger-Template:
        // cisco devices return this string if snmp is disabled
        %SNMP agent not enabled
       
    Trigger-Commands:
        SET: $snmpEnabled = "false"
       
    ########################################################################
    Trigger:
        Determine RW String

    Trigger-Description:
        Determine whether the string should be Read-Write or Read-Only
       
    Trigger-Filter:
        true
       
    Trigger-Commands:{$RW eq "off"}
        SET: $RW = "RO"
       
    Trigger-Commands:{$RW eq "on"}
        SET: $RW = "RW"
       
    ########################################################################
    Trigger:
        Add Community String

    Trigger-Description:
        Adds the given community string to the device(s)
       
    Trigger-Filter:
        $snmpEnabled eq "true"

    Trigger-Commands:
        //cisco commands to add string here
        snmp-server community $NewCommunityString $RW
       

    Output-Triggers:
        Community String Added

    ########################################################################
    Issue:
        Community String Added

    Issue-ID:
        newCommunityString
       
    Issue-Severity:
        Info
       
    Issue-Description:
        Show which devices the community string was added to, and the string added

    Issue-Filter:
        $snmpEnabled eq "true"
       
    Issue-Details:
             Host                $IPAddress
              Name                $Name
        Community String    $NewCommunityString
        RW or RO        $RW

    ########################################################################
    Issue:
        SNMP Disabled

    Issue-ID:
        snmpDisabled
       
    Issue-Severity:
        Error
       
    Issue-Description:
        SNMP is not enabled on this device

    Issue-Filter:
        $snmpEnable eq "false"
       
    Issue-Details:
             Host                $IPAddress
              Name                $Name

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

    Mike Griffin
    Netcordia TAC
    support@netcordia.com
    Filed under: ,
  • 05-15-2008 9:43 AM In reply to

    Re: Add SNMP Community String

     Here is a simple version of the above script.

     

    Script:
        Add SNMP community String

    Script-Description:
        This script checks to see if the User Specified Community String
        Exists. If it does not then the new community string is added.
       
    Script-Filter:
        $Vendor eq "Cisco"
        and $sysDesc like /IOS/

    Script-Variables:
        $NewCommunityString    string
           
    ########################################################################
    Action:
        Check for Present Community String

    Action-Description:
        Ensure our specified community string isn't in the running config

    Action-Commands:
        SET: $communityMatch = "false"
        show run
       
    Output-Triggers:
        Parse Output
       
    ########################################################################
    Trigger:
        Parse Output

    Trigger-Description:
        Check for the community string
       
    Trigger-Variable:
            $communityString string
       
    Trigger-Template:
        snmp-server community [[$communityString]] (RO|RW)
       
    Trigger-Commands:{$communityString eq $NewCommunityString}
        SET: $communityMatch = "true"
       
    Output-Triggers:
        Add Community String
       
    ########################################################################
    Trigger:
        Add Community String

    Trigger-Description:
        Adds the given community string to the device(s)if it is not already
        configured
       
    Trigger-Commands:{$communityMatch eq "false"}
        conf snmp add community readonly $NewCommunityString
        save
        yes

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

     

    Mike Griffin
    Netcordia TAC
    support@netcordia.com
Page 1 of 1 (2 items)