Ejemplo n.º 1
0
/* Register mib nodes from Lua */
static int
snmpd_mib_node_reg(lua_State *L)
{
  oid_t *inst_id;
  int inst_id_len;
  const char *inst_cb;
  int i;

  /* Check if the first argument is a table. */
  luaL_checktype(L, 1, LUA_TTABLE);

  /* Get oid length */
  inst_id_len = lua_objlen(L, 1);
  /* Get oid */
  inst_id = xmalloc(inst_id_len * sizeof(oid_t));
  for (i = 0; i < inst_id_len; i++) {
    lua_rawgeti(L, 1, i + 1);
    inst_id[i] = lua_tointeger(L, -1);
    lua_pop(L, 1);
  }

  /* Get lua callback of instance node */
  inst_cb = luaL_checkstring(L, 2);
  /* Register node */
  i = mib_node_reg(inst_id, inst_id_len, inst_cb);
  /* Get returned value */
  lua_pushnumber(L, i);

  free(inst_id);

  return 1;
}
Ejemplo n.º 2
0
/* Register mib group node */
static int
agentx_mib_node_reg(const oid_t *grp_id, int id_len, int grp_cb)
{
  struct x_pdu_buf x_pdu;

  /* Check oid prefix */
  if (id_len < 4 || grp_id[0] != 1 || grp_id[1] != 3 || grp_id[2] != 6 || grp_id[3] != 1) {
    SMARTSNMP_LOG(L_ERROR, "Oid prefix must be .1.3.6.1!\n");
    return -1;
  }

  /* Send agentX register PDU */
  x_pdu = agentx_register_pdu(&agentx_datagram, grp_id, id_len, NULL, 0, 0, 127, 0, 0);
  if (send(agentx_datagram.sock, x_pdu.buf, x_pdu.len, 0) == -1) {
    SMARTSNMP_LOG(L_ERROR, "Send agentX register PDU failure!\n");
    return -1;
  }

  /* Receive agentX resoponse PDU */
  x_pdu.len = TRANS_BUF_SIZ;
  x_pdu.buf = xrealloc(x_pdu.buf, x_pdu.len);
  x_pdu.len = recv(agentx_datagram.sock, x_pdu.buf, x_pdu.len, 0);
  if (x_pdu.len == -1) {
    SMARTSNMP_LOG(L_ERROR, "Receive agentX register response PDU failure!\n");
    return -1;
  }

  /* Verify register response PDU */
  if (agentx_recv(x_pdu.buf, x_pdu.len) != AGENTX_ERR_OK) {
    SMARTSNMP_LOG(L_ERROR, "Parse agentX rigister response PDU error!\n");
    return -1;
  }

  /* Register node */
  return mib_node_reg(grp_id, id_len, grp_cb);
}
Ejemplo n.º 3
0
/* Register mib group node */
static int
snmpd_mib_node_reg(const oid_t *grp_id, int id_len, int grp_cb)
{
  return mib_node_reg(grp_id, id_len, grp_cb);
}