This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

SNMP send orders
#3
(27.11.2023, 08:37)admin Wrote: See this thread for examples: https://forum.logicmachine.net/showthrea...6#pid13456
Look for "Confusedet" function calls.
I can't get it to work, I send it 1 and it gives me an error


snmp set to 192,168,1,33 1.3.6.1.4.1.41809.2.52.0 failed: snmp bad type(2) prim=0 in index 1


thank you


Code:
require('snmp')
function setSNMPValue(ip, oid, value, type)
  type = type or snmp.INTEGER  -- Valor predeterminado: snmp.INTEGER si no se especifica el tipo
  local conn, err = snmp.open({
    version = snmp.SNMPv1,
    community = 'public',
    peer = ip,
  })
  if conn then
    local res, err = conn:set({
      {
        oid = oid,
        value = value,
        type = type,
      }
    })
    if err then
      alert('snmp set to ' .. ip .. ' ' .. oid .. ' failed: ' .. tostring(err))
    else
      alert('snmp set to ' .. ip .. ' ' .. oid .. ' ok')
      -- Realizar una operación GET para verificar si el valor se ha establecido correctamente
      local res_get, err_get = conn:get(oid)
      if res_get and res_get.value == value then
        alert('Verification: snmp get for ' .. ip .. ' ' .. oid .. ' successful')
      else
        alert('Verification: snmp get for ' .. ip .. ' ' .. oid .. ' failed')
      end
    end
    conn:close()
  else
    alert('snmp connection to ' .. ip .. ' failed: ' .. tostring(err))
  end
end
-- Ejemplos de uso con valores enteros
setSNMPValue('192.168.1.33', '1.3.6.1.4.1.41809.2.52.0', 1, snmp.INTEGER)
setSNMPValue('192.168.1.33', '1.3.6.1.4.1.41809.2.53.0', 3, snmp.INTEGER)
-- Agrega más llamadas según sea necesario para otros dispositivos o parámetros SNMP
Reply


Messages In This Thread
SNMP send orders - by nmedalacabeza - 24.11.2023, 18:14
RE: SNMP send orders - by admin - 27.11.2023, 08:37
RE: SNMP send orders - by nmedalacabeza - 16.12.2023, 20:51
RE: SNMP send orders - by admin - 18.12.2023, 07:36
RE: SNMP send orders - by nmedalacabeza - 19.12.2023, 05:49

Forum Jump: