Roxen.git / server / base_server / snmpagent.pike

version» Context lines:

Roxen.git/server/base_server/snmpagent.pike:1:   /* -  * $Id: snmpagent.pike,v 1.10 2001/08/17 01:20:16 hop Exp $ +  * $Id: snmpagent.pike,v 1.11 2001/08/22 14:41:18 hop Exp $    *    * The Roxen SNMP agent    * Copyright © 2001, Roxen IS.    *    * Author: Honza Petrous    * January 2001         RFC 1213 base MIB    system.* (all done)
Roxen.git/server/base_server/snmpagent.pike:24:       Known issues:    - every reload spawne a new thread, I guess that old ones are never    used then. [threads leak] // FIXME: solved by switching to the async i/o    - the OID must be minimally 5 elements long, otherwise GETNEXT return    "no such name" error    - default value for snmpagent host/port variable in the config. int.    hasn't set correctly hostname part // FIXME: how reach config.int.'s URL    from define_global_variables ?    - cold_start trap code isn't completed -  - tabular walking throught roxenis.app.roxen.* doesn't working +  - tabular walking throught roxenis.app.webserver.* doesn't working    Todos:    v1.0 todo:    - cold/warm start trap generation    - restart/stop    - 'basic' Roxen working variables       v1.1 todo:    - trap handling    - module reloading   
Roxen.git/server/base_server/snmpagent.pike:90:   //! The starting part of OID of every object will have, so we stripp it out   //! before making index from OID to the MIB DB   #define MIBTREE_BASE "1.3.6.1"      #define RISMIB_BASE_ADD "4.1.8614"   // enterprises.roxenis   #define RISMIB_BASE MIBTREE_BASE+"."+RISMIB_BASE_ADD   #define RISMIB_BASE_WEBSERVER_ADD "1.1"   // enterprises.roxenis.app.roxen   #define RISMIB_BASE_WEBSERVER RISMIB_BASE+"."+RISMIB_BASE_WEBSERVER_ADD - // enterprises.roxenis.app.roxen.global + // enterprises.roxenis.app.webserver.global   #define RISMIB_BASE_WEBSERVER_GLOBAL RISMIB_BASE_WEBSERVER+".1" - // enterprises.roxenis.app.roxen.global.vs - #define RISMIB_BASE_WEBSERVER_GLOBAL_VS RISMIB_BASE_WEBSERVER_GLOBAL+".1" - // enterprises.roxenis.app.roxen.global.restart - #define RISMIB_BASE_WEBSERVER_GLOBAL_BOOT RISMIB_BASE_WEBSERVER_GLOBAL+".2" - // enterprises.roxenis.app.roxen.vs - #define RISMIB_BASE_WEBSERVER_VS RISMIB_BASE_WEBSERVER+".2" - // enterprises.roxenis.app.roxen.vs.name - #define RISMIB_BASE_WEBSERVER_VS_NAME RISMIB_BASE_WEBSERVER_VS+".1" - // enterprises.roxenis.app.roxen.vs.sentdata - #define RISMIB_BASE_WEBSERVER_VS_SDATA RISMIB_BASE_WEBSERVER_VS+".2" - // enterprises.roxenis.app.roxen.vs.senthdrs - #define RISMIB_BASE_WEBSERVER_VS_SHDRS RISMIB_BASE_WEBSERVER_VS+".3" - // enterprises.roxenis.app.roxen.vs.recvdata - #define RISMIB_BASE_WEBSERVER_VS_RDATA RISMIB_BASE_WEBSERVER_VS+".4" - // enterprises.roxenis.app.roxen.vs.requests - #define RISMIB_BASE_WEBSERVER_VS_REQS RISMIB_BASE_WEBSERVER_VS+".5" + // enterprises.roxenis.app.webserver.global.restart + #define RISMIB_BASE_WEBSERVER_GLOBAL_BOOT RISMIB_BASE_WEBSERVER_GLOBAL+".1" + // enterprises.roxenis.app.webserver.vsTable.vsEntry + #define RISMIB_BASE_WEBSERVER_VS RISMIB_BASE_WEBSERVER+".2.1" + // enterprises.roxenis.app.webserver.vsTable.vsEntry.vsIndex + #define RISMIB_BASE_WEBSERVER_VS_INDEX RISMIB_BASE_WEBSERVER_VS+".1" + // enterprises.roxenis.app.webserver.vsTable.vsEntry.vsName + #define RISMIB_BASE_WEBSERVER_VS_NAME RISMIB_BASE_WEBSERVER_VS+".2" + // enterprises.roxenis.app.webserver.vsTable.vsEntry.vsDescription + #define RISMIB_BASE_WEBSERVER_VS_DESC RISMIB_BASE_WEBSERVER_VS+".3" + // enterprises.roxenis.app.webserver.vsTable.vsEntry.vsSent + #define RISMIB_BASE_WEBSERVER_VS_SDATA RISMIB_BASE_WEBSERVER_VS+".4" + // enterprises.roxenis.app.webserver.vsTable.vsEntry.vsReceived + #define RISMIB_BASE_WEBSERVER_VS_RDATA RISMIB_BASE_WEBSERVER_VS+".5" + // enterprises.roxenis.app.webserver.vsTable.vsEntry.vsHeaders + #define RISMIB_BASE_WEBSERVER_VS_SHDRS RISMIB_BASE_WEBSERVER_VS+".6" + // enterprises.roxenis.app.webserver.vsTable.vsEntry.vsRequests + #define RISMIB_BASE_WEBSERVER_VS_REQS RISMIB_BASE_WEBSERVER_VS+".7"      #define LOG_EVENT(txt, pkt) log_event(txt, pkt)      class SNMPagent {    private int enabled;       // Global variables    private object fd; // opened UDP port    private int inited; // flag    private int snmpinpkts;
Roxen.git/server/base_server/snmpagent.pike:418:    return(1);    }       //! Returns name of the virtual server    string get_virtservname(int vsid) {    if(zero_type(vsdb[vsid]))    return 0; // bad index number    return (roxen->configurations[vsid]->name);    }    +  //! Returns description of the virtual server +  string get_virtservdesc(int vsid) { +  if(zero_type(vsdb[vsid])) +  return 0; // bad index number +  return "blahblah!"; //(roxen->configurations[vsid]->name); +  } +     //! Returns send data statistics of the virtual server    int get_virtservsdata(int vsid) {    if(zero_type(vsdb[vsid]))    return -1; // bad index number    return (roxen->configurations[vsid]->sent);    }       //! Returns received data statistics of the virtual server    int get_virtservrdata(int vsid) {    if(zero_type(vsdb[vsid]))
Roxen.git/server/base_server/snmpagent.pike:530:       //! Returns array. First element is type of second element.    //! Is usable for very primitive managed objects, in which case the value    //! is got by calling function from submibtab table.    //array `[](string oid) {    array get(string oid, mapping|void pkt) {       function rval;    string soid;    -  SNMPAGENT_MSG(sprintf("GET(%s): %O", name, oid)); +  SNMPAGENT_MSG(sprintf("%s: GET(%O) from %s@%s:%d", name, oid, pkt->community, pkt->ip,pkt->port));    soid = oid_strip(oid);    if (functionp(rval = submibtab[soid])) {    SNMPAGENT_MSG("found MIB object.");    return rval();    }       // hmm, now we have to try some of the registered managers    array s = soid/".";    for(int cnt = sizeof(s)-1; cnt>0; cnt--) {    SNMPAGENT_MSG(sprintf("finding manager for tree %O", s[..cnt]*"."));    if(subtreeman[s[..cnt]*"."]) {    // good, subtree manager exists    string manoid = s[..cnt]*".";    SNMPAGENT_MSG(sprintf("found subtree manager: %s(%O)",    subtreeman[manoid]->name, manoid)); -  return subtreeman[manoid]->get(oid); +  return subtreeman[manoid]->get(oid, pkt);    }    }       SNMPAGENT_MSG("Not found any suitable manager");    return 0;    }       //! Returns array ({ nextoid, type, val }) or 0    array|int getnext(string oid, mapping|void pkt) {       array(string) idxnums = Array.sort(indices(submibtab));    int idx;    string soid;    array s;    -  SNMPAGENT_MSG(sprintf("GETNEXT(%s): %O", name, oid)); +  SNMPAGENT_MSG(sprintf("%s: GETNEXT(%O) from %s@%s:%d", name, oid, pkt->community, pkt->ip,pkt->port));    if(!(soid = oid_strip(oid)))    return 0;    idx = search(idxnums, soid);    if(idx >= 0) {    // good, we found equality    SNMPAGENT_MSG(sprintf("%s: eq match: %O", tree, idx));    if(idx < sizeof(idxnums)-1)    return (({ MIBTREE_BASE+"."+(string)idxnums[idx+1],    @submibtab[idxnums[idx+1]]() }));    else
Roxen.git/server/base_server/snmpagent.pike:652:       //! External function for MIB object returning nothing    array get_null() { return OBJ_COUNT(0); }      } // SubMIBManager      // base external feeders      //! External function for MIB object 'system.sysDescr'   array get_description() { -  return OBJ_STR("Roxen Webserver SNMP agent v"+("$Revision: 1.10 $"/" ")[1]+" (devel. rel.)"); +  return OBJ_STR("Roxen Webserver SNMP agent v"+("$Revision: 1.11 $"/" ")[1]+" (devel. rel.)");   }      //! External function for MIB object 'system.sysOID'   array get_sysoid() {    return OBJ_OID(RISMIB_BASE_WEBSERVER);   }      //! External function for MIB object 'system.sysUpTime'   array get_uptime() {    return OBJ_TICK((time(1) - roxen->start_time)*100);
Roxen.git/server/base_server/snmpagent.pike:804:       }   }      //! roxenis enterprise subtree manager   //! Manages the enterprise.roxenis.* submib tree.   class SubMIBRoxenVS {       inherit SubMIBManager;    -  constant name = "enterprises.roxenis.app.roxen.global.vs"; -  constant tree = RISMIB_BASE_WEBSERVER_GLOBAL_VS - (MIBTREE_BASE+"."); +  constant name = "enterprises.roxenis.app.webserver.vsTable"; +  constant tree = RISMIB_BASE_WEBSERVER_VS - (MIBTREE_BASE+".");       void create(object agent) {       submibtab = ([    // enterprises    // hack2 :)    tree+".0": agent->get_virtserv,    ]);    }   }
Roxen.git/server/base_server/snmpagent.pike:850:    if(attrval == 0 || attrval == 1) {    report_warning("SNMPagent: Requested " + attrval?"en":"dis" + "abling of auth. traps from snmp://" + pdata[msgid]->community + "@" + pdata[msgid]->ip + "/\n");    // here will be ena/disabling of such traps    }    } else    snmpbadcommuses++;    break;   */      //! roxenis enterprise subtree manager - //! Manages the enterprise.roxenis.* submib tree. + //! Manages the enterprises.roxenis.app.webserver.vsTable submib tree.   class SubMIBRoxenVSName {       inherit SubMIBManager;    -  constant name = "enterprises.roxenis.app.roxen.vs"; +  constant name = "enterprises.roxenis.app.webserver.vsTable";    constant tree = RISMIB_BASE_WEBSERVER_VS - (MIBTREE_BASE+".");       object agent;       void create(object agentp) {    agent = agentp;    submibtab = ([ ]);    }       array get(string oid, mapping|void pkt) {       string soid, vname; -  int vdata; +  int vdata, idx;    array rval, arroid;    -  SNMPAGENT_MSG(sprintf("GET(%s): %O", name, oid)); +  SNMPAGENT_MSG(sprintf("%s: GET(%O) from %s@%s:%d", name, oid, pkt->community, pkt->ip,pkt->port));    soid = oid_strip(oid);       /* fist, we will try to find an "ordinary" object in the MIB    if (functionp(rval = submibtab[soid])) {    SNMPAGENT_MSG("found ordinary MIB object.");    return rval();    }*/       // no, so we will try to find "tabular" object instead    if(sizeof((soid = soid - (tree + "."))/".") != 2)    return ({}); // exactly one point, please    -  +  idx = ((int)(soid/".")[1])+1;    switch ((soid/".")[0]) {    -  case "1": // VS_NAME -  vname = agent->get_virtservname(((int)(soid/".")[1])+1); +  case "1": // VS_INDEX +  vname = agent->get_virtservname(idx);    if(!stringp(vname))    return ({}); // wrong index -  +  return (OBJ_INT(idx)); +  +  case "2": // VS_NAME +  vname = agent->get_virtservname(idx); +  if(!stringp(vname)) +  return ({}); // wrong index    return (OBJ_STR(vname));    -  case "2": // VS_SDATA -  vdata = agent->get_virtservsdata(((int)(soid/".")[1])+1); +  case "3": // VS_DESC +  vname = agent->get_virtservdesc(idx); +  if(!stringp(vname)) +  return ({}); // wrong index +  return (OBJ_STR(vname)); +  +  case "4": // VS_SDATA +  vdata = agent->get_virtservsdata(idx);    if(vdata < 0)    return ({}); // wrong index    return (OBJ_COUNT(vdata));    -  case "3": // VS_SHDRS -  vdata = agent->get_virtservshdrs(((int)(soid/".")[1])+1); +  case "5": // VS_RDATA +  vdata = agent->get_virtservrdata(idx);    if(vdata < 0)    return ({}); // wrong index    return (OBJ_COUNT(vdata));    -  case "4": // VS_RDATA -  vdata = agent->get_virtservrdata(((int)(soid/".")[1])+1); +  case "6": // VS_SHDRS +  vdata = agent->get_virtservshdrs(idx);    if(vdata < 0)    return ({}); // wrong index    return (OBJ_COUNT(vdata));    -  case "5": // VS_REQS -  vdata = agent->get_virtservreqs(((int)(soid/".")[1])+1); +  case "7": // VS_REQS +  vdata = agent->get_virtservreqs(idx);    if(vdata < 0)    return ({}); // wrong index    return (OBJ_COUNT(vdata));       }    return ({});       }       array getnext(string oid, mapping|void pkt) {       string soid, noid, vname;    int idx, vdata;    array rval, arr;    -  SNMPAGENT_MSG(sprintf("GETNEXT(%s): %O", name, oid)); +  SNMPAGENT_MSG(sprintf("%s: GETNEXT(%O) from %s@%s:%d", name, oid, pkt->community, pkt->ip,pkt->port));    soid = oid_strip(oid);       if(oid == (MIBTREE_BASE+"."+tree)) {    soid = "1.-1"; // special case    oid += ".1.-1"; // trash only    }       arr = ((soid = soid - (tree + "."))/".");    if(sizeof(arr) == 1) {    soid = arr[0]+".-1"; // special case
Roxen.git/server/base_server/snmpagent.pike:983:    return ({}); // wrong index    return (({noid, @OBJ_COUNT(vdata)}));       }    return ({});    }      }       + //! Manages the enterprises.roxenis.app.webserver.global.boot object   class SubMIBRoxenBoot {       inherit SubMIBManager;    -  constant name = "enterprises.roxenis.app.roxen.global.boot"; +  constant name = "enterprises.roxenis.app.webserver.global.boot";    constant tree = RISMIB_BASE_WEBSERVER_GLOBAL_BOOT - (MIBTREE_BASE+".");       object agent;       void create(object agentp) {    agent = agentp;    submibtab = ([ ]);    }       // HACK! For testing purpose only!