Roxen.git / server / base_server / snmpagent.pike

version» Context lines:

Roxen.git/server/base_server/snmpagent.pike:1:   /* -  * $Id: snmpagent.pike,v 1.6 2001/07/19 20:23:02 hop Exp $ +  * $Id: snmpagent.pike,v 1.7 2001/08/14 01:47:17 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:20:   RFC 2576 Coexistence between v1, v2 and v3 of SNMP protocol   RFC 2594 Definitions of managed objects for WWW services      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 ?    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:48:   inherit "global_variables";   inherit Roxen;   #define roxen roxenp()            // FIXME: thread leaking is hiden by moving to the async i/o model   //#define NO_THREADS !constant(thread_create)   #define NO_THREADS 1    - //#define SNMPAGENT_DEBUG 1 +    #ifdef SNMPAGENT_DEBUG   # define SNMPAGENT_MSG(X) report_notice("SNMPagent: "+X+"\n")   # define SNMPAGENT_MSGS(X, Y) report_notice("SNMPagent: "+X+"\n", @Y)   #else   # define SNMPAGENT_MSG(X)   # define SNMPAGENT_MSGS(X, Y)   #endif    -  + //! Default port number for agent + #ifndef SNMPAGENT_DEFAULT_PORT + #define SNMPAGENT_DEFAULT_PORT 1610 + #endif +    #define SNMP_OP_GETREQUEST 0   #define SNMP_OP_GETNEXT 1   #define SNMP_OP_GETRESPONSE 2   #define SNMP_OP_SETREQUEST 3   #define SNMP_OP_TRAP 4      #define OBJ_STR(x) ({"str", x})   #define OBJ_INT(x) ({"int", x})   #define OBJ_OID(x) ({"oid", x})   #define OBJ_TICK(x) ({"tick", x})
Roxen.git/server/base_server/snmpagent.pike:114:          void create() {    vsdb = ([]);    //disable();    }       //! Enable SNMPagent processing.    int enable() {    +  if(enabled) +  return(enabled);    mib = SubMIBsystem(); // system.* table    if(objectp(mib)) {    // snmp.*    mib->register(MIBTREE_BASE+"."+"2.1.11", SubMIBsnmp(this_object()));    // enterprises.roxenis.*    mib->register(MIBTREE_BASE+"."+"4.1.8614", SubMIBroxenis(this_object()));    }    if (!status())    start();    enabled = 1;
Roxen.git/server/base_server/snmpagent.pike:171:    private void process_query(mapping data) {       mapping pdata, rdata = ([]);    int msgid, op, errnum = 0, setflg = 0;    string attrname, comm;    array val;       snmpinpkts++;    pdata = fd->decode_asn1_msg(data);    -  SNMPAGENT_MSG(sprintf("Got parsed: %O", pdata)); +  //SNMPAGENT_MSG(sprintf("Got parsed: %O", pdata));       if(!mappingp(pdata)) {    SNMPAGENT_MSG("SNMP message can not be decoded. Silently ommited.");    return;    }       msgid = indices(pdata)[0];    comm = pdata[msgid]->community || "";    op = pdata[msgid]->op;   
Roxen.git/server/base_server/snmpagent.pike:243:       //SNMPAGENT_MSG(sprintf("Answer: %O", rdata));    snmpoutpkts++;    if(!sizeof(rdata)) {    if (!errnum) LOG_EVENT("No such name", pdata[msgid]);    fd->get_response(([attrname:({"oid", attrname})]), pdata, errnum || 2 /*SNMP_NOSUCHNAME*/);    } else    fd->get_response(rdata, pdata);    }    +  //! Returns domain name of the config. int. virtual server +  private string get_cif_domain() { +  +  return(Standards.URI(roxen->configurations[0]->get_url()||"http://0.0.0.0")->host); +  } +     //! Opens the SNMP port. Then waits for the requests.    private void real_start() {       mixed err;    mapping data;    array hp = query("snmp_hostport")/":"; -  int p = (sizeof(hp)>1) ? (int)hp[1] : 161; // FIXME: SNMPAGENT_DEFAULT_PORT !!! +  int p = (sizeof(hp)>1) ? (int)hp[1] : (int)SNMPAGENT_DEFAULT_PORT;    -  +  if(!sizeof(hp[0])) +  hp[0] = get_cif_domain();    err = catch( fd = Protocols.SNMP.protocol(0, hp[0], p||161) );    if(arrayp(err))    RXML.run_error("SNMPagent: can't open UDP port " + hp[0]+":"+(string)(p||161)+"[" + err[0] + "].");    SNMPAGENT_MSG(sprintf("SNMP UDP port %s:%d binded successfully.", hp[0], p||161));       enabled = 1;   #if NO_THREADS    // set callbacks    fd->set_nonblocking(process_query);   #else
Roxen.git/server/base_server/snmpagent.pike:317:       //! 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, vsdb[vsid]->variables["snmp_traphosts"])); -  foreach(vsdb[vsid]->variables["snmp_traphosts"], string thost) { +  SNMPAGENT_MSG(sprintf("virt.serv[%d/%s]'s traphosts:%O", +  vsid, vsdb[vsid]->name, +  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)); -  fd->trap(RISMIB_BASE_WEBSERVER, -  Standards.URI(vsdb[vsid]->varibles["MyWorldLocation"])->host, -  0, 0, -  get_uptime(), 0, uri->host, uri->port); + /* +  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));       }       //! Warm start notificator    void warmstart_trap() {
Roxen.git/server/base_server/snmpagent.pike:353:       //! 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:DEB: add: %O->%O\n",vsid,roxen->configurations[vsid]->name)); +  report_debug(sprintf("snmpagent: virt.serv.[%d/%s] added.\n", +  vsid,roxen->configurations[vsid]->name));   //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])) { - report_debug(sprintf("snmpagent:DEB: del: %O->%O\n",vsid,roxen->configurations[vsid]->name)); + SNMPAGENT_MSG(sprintf("snmpagent:DEB: del: %O->%O\n",vsid,roxen->configurations[vsid]->name));    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:541:       //! 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.6 $"/" ")[1]+" (devel. rel.)"); +  return OBJ_STR("Roxen Webserver SNMP agent v"+("$Revision: 1.7 $"/" ")[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:701:    inherit SubMIBManager;       constant name = "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.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])) {