Roxen.git / server / base_server / snmpagent.pike

version» Context lines:

Roxen.git/server/base_server/snmpagent.pike:1:   /* -  * $Id: snmpagent.pike,v 1.7 2001/08/14 01:47:17 hop Exp $ +  * $Id: snmpagent.pike,v 1.8 2001/08/14 23:24:35 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:23:   Developer notes:       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    Todos:    v1.0 todo:    - cold/warm start trap generation    - 'basic' Roxen working variables       v1.1 todo:    - trap handling       v2.0 todo:    - Roxen.module API for registering MIB subtree
Roxen.git/server/base_server/snmpagent.pike:123:    void create() {    vsdb = ([]);    //disable();    }       //! Enable SNMPagent processing.    int enable() {       if(enabled)    return(enabled); -  mib = SubMIBsystem(); // system.* table +  mib = SubMIBSystem(); // system.* table    if(objectp(mib)) {    // snmp.* -  mib->register(MIBTREE_BASE+"."+"2.1.11", SubMIBsnmp(this_object())); +  mib->register(MIBTREE_BASE+"."+"2.1.11", SubMIBSnmp(this_object()));    // enterprises.roxenis.* -  mib->register(MIBTREE_BASE+"."+"4.1.8614", SubMIBroxenis(this_object())); +  mib->register(MIBTREE_BASE+"."+"4.1.8614", SubMIBRoxenIS(this_object())); +  mib->register(MIBTREE_BASE+"."+"4.1.8614.1.1.999.2.1.1", SubMIBRoxenVs(this_object()));    }    if (!status())    start();    enabled = 1;    return (enabled);    }       //! Disable SNMPagent processing.    int disable() {   
Roxen.git/server/base_server/snmpagent.pike:210:    attrname = indices(attrs)[0];       if(!mib) {    SNMPAGENT_MSG(" MIB table isn't loaded!\n");    // what to do now ?    }    switch(op) {       case SNMP_OP_GETREQUEST:    val = mib->get(attrname, pdata[msgid]); -  if (arrayp(val) && val[0]) +  if (arrayp(val) && sizeof(val) && val[0])    rdata[attrname] += val;    break;       case SNMP_OP_GETNEXT:    val = mib->getnext(attrname, pdata[msgid]); -  if (arrayp(val) && val[0]) +  if (arrayp(val) && sizeof(val) && val[0])    //rdata[attrname] += val;    rdata[val[0]] += val[1..2];    break;       case SNMP_OP_SETREQUEST:    val = mib->set(attrname, attrval, pdata[msgid]); -  if(arrayp(val)) +  if(arrayp(val) && sizeof(val))    setflg = val[0];    //rdata[attrname] += ({ "int", attrval });    rdata["1.3.6.1.2.1.1.3.0"] += ({"tick", get_uptime() });    if (arrayp(val) && stringp(val[1]))    report_warning(val[1]);    break;          } //switch    //else
Roxen.git/server/base_server/snmpagent.pike:332:    }       //! Cold start notificator. Sends trap for all virtual servers in the vsarr.    void coldstart_trap(array(int) vsarr) {       object uri;       if(intp(vsarr))    return;    foreach(vsarr, int vsid) -  if(vsdb[vsid] && vsdb[vsid]->variables["snmp_traphosts"]) { -  SNMPAGENT_MSG(sprintf("virt.serv[%d/%s]'s traphosts:%O", -  vsid, vsdb[vsid]->name, +  if(vsdb[vsid] && vsdb[vsid]->variables["snmp_traphosts"] && sizeof(vsdb[vsid]->variables["snmp_traphosts"]->query())) { +  SNMPAGENT_MSG(sprintf("server %O(#%d): traphosts:%O", +  vsdb[vsid]->name, vsid,    vsdb[vsid]->variables["snmp_traphosts"]->query()));    foreach(vsdb[vsid]->variables["snmp_traphosts"]->query(), mixed thost) {    uri = Standards.URI(thost); -  SNMPAGENT_MSG(sprintf("Trap sent: %s.", thost)); +  SNMPAGENT_MSG(sprintf("Trap sent: %s", thost));   /*    fd->trap(    ([RISMIB_BASE_WEBSERVER+".999.1.1":    ({ "str", Standards.URI(vsdb[vsid]->variables["MyWorldLocation"]->query())->host}) ]),    uri->host, uri->port);   */    }    } else    if(vsdb[vsid]) -  SNMPAGENT_MSG(sprintf("virt.serv[%d/%O] hasn't any traphosts.", -  vsid, vsdb[vsid] && vsdb[vsid]->name)); +  SNMPAGENT_MSG(sprintf("server %O(#%d) hasn't any traphosts.", +  vsdb[vsid] && vsdb[vsid]->name, vsid));       }       //! Warm start notificator    void warmstart_trap() {       }       //! Authentication failure notificator    void authfailure_trap() {
Roxen.git/server/base_server/snmpagent.pike:372:       //! Enterprise specific trap notificator    void enterprise_trap() {       }       //! Adds virtual server to the DB of managed objects    int add_virtserv(int vsid) {       if(zero_type(vsdb[vsid])) { -  report_debug(sprintf("snmpagent: virt.serv.[%d/%s] added.\n", -  vsid,roxen->configurations[vsid]->name)); +  report_debug(sprintf("SNMPagent: added server %O(#%d)\n", +  roxen->configurations[vsid]->name, vsid));   //report_debug(sprintf("snmpagent:DEB: %O\n",mkmapping(indices(roxen->configurations[vsid]), values(roxen->configurations[vsid]))));    vsdb += ([vsid: roxen->configurations[vsid]]);    }       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);    }       //! Deletes virtual server's specific objects from DB    int del_virtserv(int vsid) {       if(!zero_type(vsdb[vsid])) { - SNMPAGENT_MSG(sprintf("snmpagent:DEB: del: %O->%O\n",vsid,roxen->configurations[vsid]->name)); +  report_debug(sprintf("SNMPagent: deleted server %O(#%d)\n", +  roxen->configurations[vsid]->name, vsid));    vsdb -= ([ vsid: 0 ]);    }       return(1);    }      } // end of SNMPagent object      //! Removes first four octets from OID string, as internal table works   //! on such stripped OIDs.
Roxen.git/server/base_server/snmpagent.pike:497:    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));    if(!(soid = oid_strip(oid)))    return 0; - SNMPAGENT_MSG(sprintf("DEB: %O", soid)); +     idx = search(idxnums, soid); - SNMPAGENT_MSG(sprintf("arr: %d, %O", idx, idxnums)); +     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    return 0;    } else { -  - SNMPAGENT_MSG(sprintf("DEB: %O - %O", soid[..(sizeof(tree)-1)], tree)); +     int tlen = sizeof(tree/".");    array sarr = soid/".";    //if(soid[..(sizeof(tree)-1)] == tree) { // only inside owned subtree    if(sizeof(sarr)>=tlen && (sarr[..tlen-1]*".") == tree) {    SNMPAGENT_MSG(name+": owned subtree found.");    // hmm, now we have to find nearest subtree    for(idx = 0; idx < sizeof(idxnums); idx++)    if (soid < idxnums[idx]) {    SNMPAGENT_MSG(sprintf("subtree match: %O", idxnums[idx]));    return (({ MIBTREE_BASE+"."+(string)idxnums[idx],    @submibtab[idxnums[idx]]() }));    }    }       SNMPAGENT_MSG(name+": foreign object detected.");    s = soid/".";    // hmm, now we have to try some of the registered managers    for(int cnt = sizeof(s)-1; cnt>0; cnt--) { - SNMPAGENT_MSG(sprintf("DEB: %d: %O", cnt, 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]->getnext(oid, pkt);    }    }       }
Roxen.git/server/base_server/snmpagent.pike:568:       //! 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.7 $"/" ")[1]+" (devel. rel.)"); +  return OBJ_STR("Roxen Webserver SNMP agent v"+("$Revision: 1.8 $"/" ")[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:605:      //! External function for MIB object 'system.sysServices'   array get_sysservices() {    return OBJ_INT(query("snmp_sysservices"));   }            //! system subtree manager   //! Manages the basic system.sys* submib tree. - class SubMIBsystem { + class SubMIBSystem {       inherit SubMIBManager;       constant name = "system";    constant tree = "2.1.1";       void create() {       submibtab = ([    // system "2.1.1"
Roxen.git/server/base_server/snmpagent.pike:638:    // system.sysServices    "2.1.1.7.0": get_sysservices,    ]);    } // create      } // SubMIBsystem         //! snmp subtree manager   //! Manages the basic snmp.snmp* submib tree. - class SubMIBsnmp { + class SubMIBSnmp {       inherit SubMIBManager;       constant name = "snmp";    constant tree = "2.1.11";       void create(object agent) {       submibtab = ([    // snmp
Roxen.git/server/base_server/snmpagent.pike:716:    // snmp.snmpEnableAuthenTraps    "2.1.11.30.0": agent->get_snmpenaauth,       ]);       }   }      //! roxenis enterprise subtree manager   //! Manages the enterprise.roxenis.* submib tree. - class SubMIBroxenis { + class SubMIBRoxenIS {       inherit SubMIBManager;    -  constant name = "roxenis"; +  constant name = "enterprises.roxenis";    constant tree = "4.1.8614";       void create(object agent) {       submibtab = ([    // enterprises    // hack2 :)    "4.1.8614.1.1.999.2.1.0": agent->get_virtserv, -  "4.1.8614.1.1.999.2.1.1": agent->get_virtservname // !! tabular op !! - // !! nedoreseno! Melo by to vracet ..2.1.1.0 az ..2.1.1.n (tj. podle velikosti) +     ]);    }   }      /*    switch (attrname) {    case RISMIB_BASE_WEBSERVER+".1.0":    // HACK! For testing purpose only!    // Server restart = 1; server shutdown = 2    if(chk_access("rw", pdata[msgid])) {
Roxen.git/server/base_server/snmpagent.pike:767:    rdata["1.3.6.1.2.1.1.3.0"] += ({"tick", get_uptime() });    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. + class SubMIBRoxenVs { +  +  inherit SubMIBManager; +  +  constant name = "roxenis.app.roxen.test.vs"; +  constant tree = "4.1.8614.1.1.999.2.1.1"; +  +  object agent; +  +  void create(object agentp) { +  +  submibtab = ([ ]); +  agent = agentp; +  } +  +  array get(string oid, mapping|void pkt) { +  +  function rval; +  string soid, vname; +  +  SNMPAGENT_MSG(sprintf("GET(%s): %O", name, oid)); +  soid = oid_strip(oid); +  +  if(sizeof((soid = soid - (tree + "."))/".") > 1) +  return ({}); // no more points, please +  +  vname = agent->get_virtservname(((int)soid)+1); +  if(!stringp(vname)) +  return ({}); // wrong index +  return (OBJ_STR(vname)); +  } +  +  array getnext(string oid, mapping|void pkt) { +  +  function rval; +  string soid, vname; +  int idx; +  +  SNMPAGENT_MSG(sprintf("GETNEXT(%s): %O", name, oid)); +  soid = oid_strip(oid); +  +  if(oid == (MIBTREE_BASE+"."+tree)) { +  soid = "-1"; // special case +  oid += ".-1"; // trash only +  } else if(sizeof((soid = soid - (tree + "."))/".") > 1) +  return ({}); // no more points, please +  +  idx = (int)soid+1; +  vname = agent->get_virtservname(idx+1); +  if(!stringp(vname)) +  return ({}); // wrong index +  soid = (reverse(reverse(oid/".")[1..])*".")+"."+(string)idx; +  return (({soid, @OBJ_STR(vname)})); +  } +  + } +    SNMPagent snmpagent;   //! Global SNMPagent object