def snmp_write_test(ip, profile): """Test that snmp write works""" testresult = { 'error_message': '', 'custom_error': '', 'status': False, 'syslocation': '' } syslocation = '1.3.6.1.2.1.1.6.0' value = '' try: snmp = Snmp( ip, profile.configuration.get("community"), profile.configuration.get("version"), ) value = safestring(snmp.get(syslocation)) snmp.set(syslocation, 's', value.encode('utf-8')) except SnmpError as error: testresult['error_message'] = error.args testresult['status'] = False except UnicodeDecodeError as error: testresult['custom_error'] = 'UnicodeDecodeError' testresult['error_message'] = error.args testresult['status'] = False else: testresult['status'] = True testresult['syslocation'] = value return testresult
def snmp_write_test(ip, community, snmp_version): """Test that snmp write works""" if not community: return False testresult = { 'error_message': '', 'custom_error': '', 'status': False, 'syslocation': '' } syslocation = '1.3.6.1.2.1.1.6.0' value = '' try: snmp = Snmp(ip, community, snmp_version) value = snmp.get(syslocation) snmp.set(syslocation, 's', value) except SnmpError as error: try: value.decode('ascii') except UnicodeDecodeError: testresult['custom_error'] = 'UnicodeDecodeError' testresult['error_message'] = error.message testresult['status'] = False else: testresult['status'] = True testresult['syslocation'] = value return testresult
def get_and_set_syslocation(ip, community): syslocation = '1.3.6.1.2.1.1.6.0' try: try: snmp = Snmp(ip, community, '2c') value = snmp.get(syslocation) snmp.set(syslocation, 's', value) except TimeOutException: snmp = Snmp(ip, community, '1') value = snmp.get(syslocation) snmp.set(syslocation, 's', value) except SnmpError: return None else: return True
def get_and_set_syslocation(ip, community): syslocation = '1.3.6.1.2.1.1.6.0' try: try: snmp = Snmp(ip, community, '2c') value = snmp.get(syslocation) snmp.set(syslocation, 's', value) except TimeOutException: snmp = Snmp(ip, community, '1') value = snmp.get(syslocation) snmp.set(syslocation, 's', value) except SnmpError: return None else: return True