Actions.SnmpActions package

Submodules

Actions.SnmpActions.common_snmp_actions module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Actions.SnmpActions.common_snmp_actions.CommonSnmpActions[source]

Bases: object

Class for standard SNMP protocol commands

add_snmp_community(port, community_string)[source]

Add the SNMP community string :param port: SNMP TRAP or Inform PORT :param community_string: SNMP community String :return:

add_snmp_v3_user(port, username, securityEngineId, authkey=None, privkey=None, authProtocol=None, privProtocol=None)[source]
Add SNMP V3 User for TRAP and Inform
Argument:
  1. port: SNMP trap or inform port.
  2. username(string) = snmp v3 username.
  3. securityEngineId(string) = SNMP v3 secure engine id which is a mandatory
    argument for any V3 user. both sender and reciver should know this id. refer: http://www.net-snmp.org/tutorial/tutorial-5/commands/snmptrap-v3.html
4.authKey(string) = Initial value of the secret authentication key.
e.g. ‘authkey1’
5.privKey(string) = Initial value of the secret encryption key.
e.g. ‘privkey1’
6.authProtocol(string) = An indication of whether messages sent on behalf of this USM user
can be authenticated, and if so, the type of authentication protocol which is used. supported protocols: usmNoAuthProtocol, usmHMACMD5AuthProtocol, usmHMACSHAAuthProtocol authProtocol=”1,3,6,1,6,3,10,1,1,2”
7.privProtocol(string) = An indication of whether messages sent on behalf
of this USM user be encrypted, and if so, the type of encryption protocol which is used. supported usmNoPrivProtocol(default), usmDESPrivProtocol, usm3DESEDEPrivProtocol, usmAesCfb128Protocol e.g. privProtocol=”1,3,6,1,6,3,10,1,2,2”

Return: True or False

browse_mib(mib_filepath, mib_filename, browse='yes')[source]

Browse the MIB File/single or multiple :param mib_filepath: Mib file path of the git url or abs file path :param mib_filename: MIB file name :param browse: Default value is ‘yes’ were only browse the mentioned MIBS mib_filename argument, if set ‘no’ will browse all the Mibs in the given Path :return: True or False

show_received_traps(system_name)[source]

Retrieve the captured SNMP Trap messages and show them in the console. Argument:

system_name: Agent system name from data file.

Return: Binary- True or False

snmp_bulkget(snmp_ver, system_name, mib_name=None, mib_index=None, mib_value=None, oid_string=None, communityname=None, snmp_timeout=60, nonrepeaters='0', maxrepetitions='10', userName=None, authKey=None, privKey=None, authProtocol=None, privProtocol=None, custom_mib_paths=None, load_mib_modules=None, lexicographicMode='False')[source]

snmp_bulkget uses the SNMP BULKGET request to query for information on a network entity :Datafile usage:

1.(string) Agents IP address. address=”192.168.1.68” 2.(string) SNMP UDP port. port=”161”
Arguments:

1.communityname : SNMP v1/v2c community string. e.g. ‘public’ 2. snmp_ver: Support for v1 and V2 and V3 1 for v1, 2 for V2, 3 for V3 3.mib_name : Name of the Management Information Base e.g. ‘IF-MIB’ 4.mib_index: MIB index name e.g. ‘ipAdEntAddr’ 5.mib_value: e.g. ‘127.0.0.1’ 6.oid_string: object identifiers (OIDs) that are available on the

managed device. e.g. ‘1.3.6.1.2.1.2.2.1.6’ which is, ifPhysAddress The physical address of the interface.

User can provide either MIB or oid_string.

7. system_name(string) = Name of the system from the input datafile 9. snmp_timeout: Number of seconds the SNMP manager will wait for a responce from SNMP Agent. In case of SNMP walk the may need to set to higher. #arguments 9-13 are only for SNMPv3 or mpModel = 2 and in that # case communityname will be None 10.userName(string) = A human readable string representing the

name of the SNMP USM user. e.g. ‘usr1’

11.authKey(string) = Initial value of the secret authentication key.

e.g. ‘authkey1’

12.privKey(string) = Initial value of the secret encryption key.

e.g. ‘privkey1’

13.authProtocol(string) = An indication of whether messages sent on behalf of this USM user

can be authenticated, and if so, the type of authentication protocol which is used. supported protocols: usmNoAuthProtocol, usmHMACMD5AuthProtocol, usmHMACSHAAuthProtocol authProtocol=’1,3,6,1,6,3,10,1,1,2’

14.privProtocol(string) = An indication of whether messages sent on behalf

of this USM user be encrypted, and if so, the type of encryption protocol which is used. supported usmNoPrivProtocol(default), usmDESPrivProtocol, usm3DESEDEPrivProtocol, usmAesCfb128Protocol e.g. privProtocol=’1,3,6,1,6,3,10,1,2,2’

15.custom_mib_paths: User can provide multiple MIB source path seperated by comma (‘,’)

Source path can be url or just absolute directory path. Refer bellow example. e.g. ‘http://<URL>/@mib@, /data/users/MIBS/’. For URL it supports http, file, https, ftp and sftp. Use @mib@ placeholder token in URL location to refer.

16.load_mib_modules: User can provide the MIBS(name) need to be loaded from the path “custom_mib_path”.

It is a string of MIB names separated by comma(‘,’)

17.lexicographicMode : “True” will return everything under given prefix plus the next table also e.g. if request 1.3.6.1 will also provide 1.3.6.2

“False” will return only under given prefix. Default its False.

  1. maxrepetitions: This specifies the maximum number of iterations over the repeating variables. The default is 10.
  2. nonrepeaters : This specifies the number of supplied variables that should not be iterated over. default is 0
Return:

status(bool)= True / False. output_dict = consists of following key value: 1.errindication: If this string is not empty, it indicates

the SNMP engine error.

2.errstatus: If this element evaluates to True,it indicates an error

in the SNMP communication.Object that generated the error is indicated by the errindex element.

3.errindex: If the errstatus indicates that an error has occurred,

this field can be used to find the SNMP object that caused the error. The object position in the result array is errindex-1.

4.result: This element contains a list of all returned SNMP object

elements. Each element is a tuple that contains the name of the object and the object value.

snmp_get(snmp_ver, system_name, mib_name=None, mib_index=None, mib_value=None, oid_string=None, communityname=None, snmp_timeout=60, userName=None, authKey=None, privKey=None, authProtocol=None, privProtocol=None, custom_mib_paths=None, load_mib_modules=None)[source]

snmp_get uses the SNMP GET request to query for information on a network entity :Datafile usage:

1.(string) Agents IP address. address=”192.168.1.68” 2.(string) SNMP UDP port. port=”161”
Arguments:

1.communityname : SNMP v1/v2c community string. e.g. ‘public’ 2. snmp_ver: Support for v1 and V2 and V3 1 for v1, 2 for V2, 3 for V3 3.mib_name : Name of the Management Information Base e.g. ‘IF-MIB’ 4.mib_index: MIB index name e.g. ‘ipAdEntAddr’ 5.mib_value: e.g. ‘127.0.0.1’ 6.oid_string: object identifiers (OIDs) that are available on the

managed device. e.g. ‘1.3.6.1.2.1.2.2.1.6’ which is, ifPhysAddress The physical address of the interface.

User can provide either MIB or oid_string.

7.system_name(string) = Name of the system from the input datafile 8.snmp_timeout: Number of seconds the SNMP manager will wait for a responce from SNMP Agent. In case of SNMP walk the may need to set to higher. #arguments 9-13 are only for SNMPv3 or mpModel = 2 and in that # case communityname will be None 9.userName(string) = A human readable string representing the

name of the SNMP USM user. e.g. ‘usr1’

10.authKey(string) = Initial value of the secret authentication key.

e.g. ‘authkey1’

11.privKey(string) = Initial value of the secret encryption key.

e.g. ‘privkey1’

12.authProtocol(string) = An indication of whether messages sent on behalf of this USM user

can be authenticated, and if so, the type of authentication protocol which is used. supported protocols: usmNoAuthProtocol, usmHMACMD5AuthProtocol, usmHMACSHAAuthProtocol authProtocol=”1,3,6,1,6,3,10,1,1,2”

13.privProtocol(string) = An indication of whether messages sent on behalf

of this USM user be encrypted, and if so, the type of encryption protocol which is used. supported usmNoPrivProtocol(default), usmDESPrivProtocol, usm3DESEDEPrivProtocol, usmAesCfb128Protocol e.g. privProtocol=”1,3,6,1,6,3,10,1,2,2”

14.custom_mib_paths: User can provide multiple MIB source path seperated by comma (‘,’)

Source path can be url or just absolute directory path. Refer bellow example. e.g. ‘http://<URL>/@mib@, /data/users/MIBS/’. For URL it supports http, file, https, ftp and sftp. Use @mib@ placeholder token in URL location to refer.

15.load_mib_modules: User can provide the MIBS(name) need to be loaded from the path “custom_mib_path”.

It is a string of MIB names separated by comma(‘,’)

Return:

status(bool)= True / False. output_dict = consists of following key value: 1.errindication: If this string is not empty, it indicates the SNMP

engine error.

2.errstatus: If this element evaluates to True, it indicates an

error in the SNMP communication.Object that generated the error is indicated by the errindex element.

3.errindex: If the errstatus indicates that an error has occurred,

this field can be used to find the SNMP object that caused the error. The object position in the result array is errindex-1.

4.result: This element contains a list of all returned SNMP object

elements. Each element is a tuple that contains the name of the object and the object value.

snmp_getnext(snmp_ver, system_name, mib_name=None, mib_index=None, mib_value=None, oid_string=None, communityname=None, snmp_timeout=60, max_rows=1, userName=None, authKey=None, privKey=None, authProtocol=None, privProtocol=None, custom_mib_paths=None, load_mib_modules=None)[source]

snmp_get_next uses the SNMP GETNEXT request to query for information on a network entity :Datafile usage:

1.(string) Agents IP address. address=”192.168.1.68” 2.(string) SNMP UDP port. port=”161”
Arguments:

1.communityname : SNMP v1/v2c community string. e.g. ‘public’ 2. snmp_ver: Support for v1 and V2 and V3 1 for v1, 2 for V2, 3 for V3 3.mib_name : Name of the Management Information Base e.g. ‘IF-MIB’ 4.mib_index: MIB index name e.g. ‘ipAdEntAddr’ 5.mib_value: e.g. ‘127.0.0.1’ 6.oid_string: object identifiers (OIDs) that are available on the

managed device. e.g. ‘1.3.6.1.2.1.2.2.1.6’ which is, ifPhysAddress The physical address of the interface.

User can provide either MIB or oid_string.
  1. system_name(string) = Name of the system from the input datafile

8. snmp_timeout: Number of seconds the SNMP manager will wait for a responce from SNMP Agent. In case of SNMP walk the may need to set to higher. 9.max_rows = By default its value is one if user wants to change the no of get next message from the given OID or MIB value they can change it with different no. #arguments 9-13 are only for SNMPv3 or mpModel = 2 and in that # case communityname will be None 10.userName(string) = A human readable string representing the

name of the SNMP USM user. e.g. ‘usr1’

11.authKey(string) = Initial value of the secret authentication key.

e.g. ‘authkey1’

12.privKey(string) = Initial value of the secret encryption key.

e.g. ‘privkey1’

13.authProtocol(string) = An indication of whether messages sent on behalf of this USM user

can be authenticated, and if so, the type of authentication protocol which is used. supported protocols: usmNoAuthProtocol, usmHMACMD5AuthProtocol, usmHMACSHAAuthProtocol authProtocol=’1,3,6,1,6,3,10,1,1,2’

14.privProtocols(string) = An indication of whether messages sent on behalf

of this USM user be encrypted, and if so, the type of encryption protocol which is used. supported usmNoPrivProtocol(default), usmDESPrivProtocol, usm3DESEDEPrivProtocol, usmAesCfb128Protocol e.g. privProtocol=’1,3,6,1,6,3,10,1,2,2)’

15.custom_mib_paths: User can provide multiple MIB source path seperated by comma (‘,’)

Source path can be url or just absolute directory path. Refer bellow example. e.g. ‘http://<URL>/@mib@, /data/users/MIBS/’. For URL it supports http, file, https, ftp and sftp. Use @mib@ placeholder token in URL location to refer.

16.load_mib_module: User can provide the MIBS(name) need to be loaded from the path “custom_mib_path”.

It is a string of MIB names separated by comma(‘,’)

Return:

status(bool)= True / False. output_dict = consists of following key value: 1.errindication: If this string is not empty, it indicates

the SNMP engine error.

2.errstatus: If this element evaluates to True,it indicates an error

in the SNMP communication.Object that generated the error is indicated by the errindex element.

3.errindex: If the errstatus indicates that an error has occurred,

this field can be used to find the SNMP object that caused the error. The object position in the result array is errindex-1.

4.result: This element contains a list of all returned SNMP object

elements. Each element is a tuple that contains the name of the object and the object value.

snmp_walk(snmp_ver, system_name, mib_name=None, mib_index=None, mib_value=None, oid_string=None, communityname=None, snmp_timeout=60, userName=None, authKey=None, privKey=None, authProtocol=None, privProtocol=None, custom_mib_paths=None, load_mib_modules=None, lexicographicMode='False')[source]

snmp_walk uses the SNMP WALK request to query for information on a network entity :Datafile usage:

1.(string) Agents IP address. address=”192.168.1.68” 2.(string) SNMP UDP port. port=”161”
Arguments:

1.communityname : SNMP v1/v2c community string. e.g. ‘public’ 2. snmp_ver: Support for v1 and V2 and V3 1 for v1, 2 for V2, 3 for V3 3.mib_name : Name of the Management Information Base e.g. ‘IF-MIB’ 4.mib_index: MIB index name e.g. ‘ipAdEntAddr’ 5.mib_value: e.g. ‘127.0.0.1’ 6.oid_string: object identifiers (OIDs) that are available on the

managed device. e.g. ‘1.3.6.1.2.1.2.2.1.6’ which is, ifPhysAddress The physical address of the interface.

User can provide either MIB or oid_string.
  1. system_name(string) = Name of the system from the input datafile

8. snmp_timeout: Number of seconds the SNMP manager will wait for a responce from SNMP Agent. In case of SNMP walk the may need to set to higher. #arguments 9-13 are only for SNMPv3 or mpModel = 2 and in that # case communityname will be None 9.userName(string) = A human readable string representing the

name of the SNMP USM user. e.g. ‘usr1’

10.authKey(string) = Initial value of the secret authentication key.

e.g. ‘authkey1’

11.privKey(string) = Initial value of the secret encryption key.

e.g. ‘privkey1’

12.authProtocol(string) = An indication of whether messages sent on behalf of this USM user

can be authenticated, and if so, the type of authentication protocol which is used. supported protocols: usmNoAuthProtocol, usmHMACMD5AuthProtocol, usmHMACSHAAuthProtocol authProtocol=’1,3,6,1,6,3,10,1,1,2’

13.privProtocol(string) = An indication of whether messages sent on behalf

of this USM user be encrypted, and if so, the type of encryption protocol which is used. supported usmNoPrivProtocol(default), usmDESPrivProtocol, usm3DESEDEPrivProtocol, usmAesCfb128Protocol e.g. privProtocol=’1,3,6,1,6,3,10,1,2,2’

14.custom_mib_paths: User can provide multiple MIB source path seperated by comma (‘,’)

Source path can be url or just absolute directory path. Refer bellow example. e.g. ‘http://<URL>/@mib@, /data/users/MIBS/’. For URL it supports http, file, https, ftp and sftp. Use @mib@ placeholder token in URL location to refer.

15.load_mib_modules: User can provide the MIBS(name) need to be loaded from the path “custom_mib_path”.

It is a string of MIB names separated by comma(‘,’)

16.lexicographicMode : “True” will return everything under given prefix plus the next table also e.g. if request 1.3.6.1 will also provide 1.3.6.2$

“False” will return only under given prefix. Default its False.

Return:

status(bool)= True / False. output_dict = consists of following key value: 1.errindication: If this string is not empty, it indicates

the SNMP engine error.

2.errstatus: If this element evaluates to True,it indicates an error

in the SNMP communication.Object that generated the error is indicated by the errindex element.

3.errindex: If the errstatus indicates that an error has occurred,

this field can be used to find the SNMP object that caused the error. The object position in the result array is errindex-1.

4.result: This element contains a list of all returned SNMP object

elements. Each element is a tuple that contains the name of the object and the object value.

start_trap_listener(system_name, custom_mib_path=None, load_mib_module='SNMPv2-MIB, SNMP-COMMUNITY-MIB')[source]

Start trap listener on Given port and IP address. It creates a socket with given port and ip.The Trap listner is only for SNMP v1 and v2c and v3. Arguments:

system_name: SNMP Agents system name from the data file. custom_mib_path: User can provide multiple MIB source path seperated by comma (‘,’)

Source path can be url or just absolute directory path. Refer bellow example. e.g. ‘http://<URL>/@mib@, /data/users/MIBS/’. For URL it supports http, file, https, ftp and sftp. Use @mib@ placeholder token in URL location to refer.
load_mib_module: User can provide the MIBS(name) need to be loaded from the path “custom_mib_path”.
It is a string of MIB names separated by comma(‘,’) e.g. “FSS-COMMON-TC,FSS-COMMON-LOG,FSS-COMMON-SMI”
Data File Usage:

<ip> : Ip of the agent. It has to be IP not a hostname. <snmp_port>: SNMP Port. UDP port e.g. 161 or 1036. <snmp_trap_port> : SNMP trap port. UDP port e.g. 162 or any othe custom port.1036

if NESNMP or any other SNMP protocol is using the 162 port please use any other port other than 162.
<community>: form this release community string is mandatory for v2 and v1 SNMP trap.
you can add multiple community like ‘public,testing’ or single like ‘public’

<snmp_username>: For SNMP v3 this and engine id are mandatory argument. e.g. ‘user_snmp1234’ <securityEngineId>: One mandatory argument for V3 trap and inform.e.g. ‘80000F150000000000000000’. For noAuthNoPriv none of the bellow attributes are required. <authkey>: Auth password. e.g. ‘authkey123’ <authProtocol>: authProtocol e.g. ‘usmHMACMD5AuthProtocol’

authProtocol(string) = An indication of whether messages sent on behalf of this USM user can be authenticated, and if so, the type of authentication protocol which is used. supported protocols: usmNoAuthProtocol, usmHMACMD5AuthProtocol, usmHMACSHAAuthProtocol

<privkey>: private key e.g. ‘privkey1’ <privProtocol>: privProtocol e.g. ‘usmDESPrivProtocol’

privProtocol(string) = An indication of whether messages sent on behalf of this USM user be encrypted, and if so, the type of encryption protocol which is used. supported usmNoPrivProtocol(default), usmDESPrivProtocol, usm3DESEDEPrivProtocol, usmAesCfb128Protocol

Return: True or False

stop_trap_listener(system_name)[source]

Stop Trap listener job Argument: system_name: Agent system name given in the data file. :return: Binary True or False

validate_trap(system_name, value, oid_string=None, match_oid_op_value_pair='no')[source]

This method will validate the Received traps from a agent. Argument:

  1. system_name: Agent System name from the data file
  2. value: The tarp infromation e.g. ‘Administrative State Down’

3. oid_string: MIB string e.g. ‘FSS-COMMON-LOG::fssTrapDescription.0’ 3. match_oid_op_value_pair: if set as ‘yes’ it will match both oid_string and value as a pair. Default value ‘no’

Returns:Binary True or False
verify_snmp_action(system_name, snmp_result, mib_string=None)[source]

Will Verify SNMP get/getnext/walk/getbulk actions. :Datafile usage:

NA
Arguments:
  1. system_name(string) = Name of the system from the input datafile

2. mib_string(string) = MIB string, in regex format e.g. if searching for ‘SNMPv2-SMI::enterprises.3861.3.2.100.1.2.0’ (’’ not included) the mib_string can be SNMPv2-SMI::enterprises.3861.3.2.100.1.2.0 or if the number will be different, the mib_string can be SNMPv2-SMI::enterprises[.d+]+ 3. result(string) = SNMP Output string, in regex format e.g. ‘1Finity-T100’

Returns:
  1. status(bool)

Module contents

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.