Changeset 1284


Ignore:
Timestamp:
01/12/07 17:12:47 (6 years ago)
Author:
ckb6
Message:

The graphs server location is now automatic, rrdbot certs auto generated, now a per host service, smarter state locking for rrdbot-script, and general release work

Location:
ccsd/trunk/crcnetd/modules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ccsd/trunk/crcnetd/modules/ccs_graph.py

    r1269 r1284  
    2525from crcnetd._utils.ccsd_session import getSession, getSessionE 
    2626from crcnetd._utils.ccsd_server import exportViaXMLRPC 
    27 from crcnetd._utils.ccsd_service import ccsd_service, ccs_service_error, \ 
    28         registerService 
    29  
     27from crcnetd._utils.ccsd_service import getServiceInstance 
    3028ccs_mod_type = CCSD_SERVER 
     29GRAPH_SERVER = "localhost:80" 
    3130 
    3231@exportViaXMLRPC(SESSION_RO, AUTH_USER) 
     
    134133@exportViaXMLRPC(SESSION_RO, AUTH_USER) 
    135134def getGraphs(session_id, host_id=-1, group_id=-1, mirror='f'): 
     135    global GRAPH_SERVER 
    136136    '''This returns data to draw graphs''' 
    137137     
     
    183183        graphs2.append(newgraph)     
    184184         
    185     return graphs2 
     185    return GRAPH_SERVER, graphs2 
    186186 
    187187@exportViaXMLRPC(SESSION_RO, AUTH_USER) 
     
    223223    if host_id == '' and len(hostList2) > 0: 
    224224        host_id = hostList2[0]["host_id"] 
     225    elif host_id == '': 
     226        host_id = 0 
    225227 
    226228    linkGraphs = getLinkGraphs(session_id) 
     
    238240        newgraph ["group_name"] = graph["group_name"] 
    239241        hostGraphs2.append(newgraph)     
    240     graphs = getGraphs(session_id) 
     242    server, graphs = getGraphs(session_id) 
    241243    times = getTimes(session_id) 
    242244    pack = [hostList2, linkGraphs2, hostGraphs2, graphs, times] 
     
    429431    res = session.execute(sql, (group_id)) 
    430432    return 1     
     433 
     434def ccs_init(): 
     435    global GRAPH_SERVER 
     436    GRAPH_SERVER = "%s:%s" % (config_get("graphs", "host", "localhost"), \ 
     437        config_get("graphs", "port", "80")) 
     438 
  • ccsd/trunk/crcnetd/modules/ccs_rrdbot.py

    r1269 r1284  
    2626from crcnetd._utils.ccsd_server import exportViaXMLRPC 
    2727from crcnetd._utils.ccsd_service import ccsd_service, ccs_service_error, \ 
    28         registerService 
    29  
     28        registerService, getServiceInstance 
     29from crcnetd._utils.ccsd_cfengine import ccs_revision 
     30from crcnetd._utils.ccsd_ca import * 
     31import os.path 
    3032import time 
     33import shutil 
    3134 
    3235ccs_mod_type = CCSD_SERVER 
    3336 
     37class rrdbot_error(ccs_service_error): 
     38    pass 
     39     
    3440@exportViaXMLRPC(SESSION_RW, AUTH_USER) 
    3541def snmp_found(session_id, hostname, classname, number, data=''): 
     
    6369    return 1 
    6470 
     71@catchEvent("interfaceAdded") 
     72def interfaceAdded(eventName, host_id, session_id, **params): 
     73    addSnmpInstruction(session_id, host_id, 3, None, None, None) 
     74 
    6575@exportViaXMLRPC(SESSION_RW, AUTH_USER) 
    6676def addSnmpInstruction(session_id, host_id, instr, param1=None, param2=None, param3=None): 
     
    8999def setSnmpState(session_id,state): 
    90100    '''Set the current state of rrdbot-script''' 
    91  
    92     session = getSessionE(session_id) 
    93     sql = "UPDATE snmp_state SET state=%s" 
    94     res = session.execute(sql, (state)) 
    95     if res and res[0][0] == 0: 
    96         return round(300-(time.time()%300)) 
     101    lock = True 
     102    session = getSessionE(session_id) 
     103 
     104    #If wanting to lock see if its already locked 
     105    if state == 1: 
     106        sql = "SELECT state FROM snmp_state" 
     107        res = session.query(sql, ()) 
     108        if res and res[0][0] != 0: 
     109            lock = False 
     110    if lock: 
     111        sql = "UPDATE snmp_state SET state=%s" 
     112        res = session.execute(sql, (state)) 
     113        return 0 
    97114    else: 
    98         return 0     
     115        return 1 
    99116         
    100117@exportViaXMLRPC(SESSION_RO, AUTH_USER) 
     
    168185        sql = "UPDATE rrdbot_class SET depends=0, poll=\'%s%s\' WHERE class_id=%%s" % (clas["poll"], ":exist") 
    169186        res2 = session.execute(sql, (clas["class_id"])) 
    170         print sql 
    171         print clas["class_id"] 
    172187     
    173188    # Delete the class and its class parts 
     
    323338    return 1 
    324339     
     340 
     341@catchEvent("revisionPrepared") 
     342def handleRevisionPrepEvent(eventName, host_id, session_id, outputDir): 
     343    """Receives callbacks to add extra information to the config revisions""" 
     344     
     345    # Get a list of hosts running the rrdbot service 
     346    rrdbot = getServiceInstance(session_id, ccs_rrdbot.serviceName) 
     347    hosts = rrdbot.getHostList() 
     348 
     349    ca = ccs_ca() 
     350 
     351    # Loop through each host and ensure that the certs/ directory is populated 
     352    for host in hosts: 
     353        try: 
     354            # Check basic path existance 
     355            hostdir = "%s/hosts/%s" % (outputDir, host) 
     356            if not os.path.isdir(hostdir): 
     357                # Host does not exist in the revision 
     358                continue 
     359            rrdbotdir = "%s/rrdbot" % (hostdir) 
     360            if not os.path.isdir(rrdbotdir): 
     361                log_warn("Host '%s' does not have rrdbot templates!" % host) 
     362                continue 
     363            # Now check for the certs directory and the certificates 
     364            certsdir = "%s/certs" % (rrdbotdir) 
     365            ensureDirExists(certsdir) 
     366            if not os.path.exists("%s/key.pem" % certsdir): 
     367                key = ca.getFile("ca/rrdbot-key.pem") 
     368                fp = open("%s/key.pem" % certsdir, "w") 
     369                fp.write(key) 
     370                fp.close() 
     371            if not os.path.exists("%s/cert.pem" % certsdir): 
     372                cert = ca.getFile("ca/rrdbot-cert.pem") 
     373                fp = open("%s/cert.pem" % certsdir, "w") 
     374                fp.write(cert) 
     375                fp.close() 
     376        except: 
     377            log_error("Could not setup rrdbot certificates for %s" % host, \ 
     378                    sys.exc_info()) 
     379     
    325380class ccs_rrdbot(ccsd_service): 
    326381 
     
    331386        # Call base class setup 
    332387        ccsd_service.__init__(self, session_id, service_id) 
    333  
    334388 
    335389    def getNetworkTemplateVariables(self): 
     
    356410                classes[clas["class_id"]]["subs"] = [] 
    357411 
    358  
    359412        variables['classes'] = classes 
     413 
     414        # Include a list of hosts that the service is enabled on 
     415        variables["hosts"] = self.getEnabledHostList() 
     416        variables["server"] = config_get_required("network", "server_name") 
     417        variables["port"] = config_get("ccsd", "port", DEFAULT_SERVER_PORT) 
     418        variables["graphport"] = config_get("graphs", "port", "80") 
    360419        return variables 
    361          
     420 
     421             
     422             
    362423    @staticmethod 
    363424    def initialiseService(): 
     
    370431        session.begin("initialising rrdbot service")         
    371432        try: 
     433             
    372434 
    373435            session.execute("INSERT INTO service (service_id, service_name, " \ 
     
    376438            service_id = session.getCountOf("SELECT currval('" \ 
    377439                    "service_service_id_seq') AS server_id", ()) 
     440                     
     441            # Read in schema and dump into database 
     442            fp = open("%s/ccs_graphs.schema" % \ 
     443                    config_get("ccsd", "service_data_dir", \ 
     444                    DEFAULT_SERVICE_DATA_DIR)) 
     445            schema = fp.readlines() 
     446            fp.close() 
     447            session.execute("\n".join(schema), ()) 
    378448 
    379449            # Commit the changeset 
     
    385455            log_error("Unable to initialise rrdbot database entries!", \ 
    386456                    sys.exc_info()) 
    387             raise quagga_error("Failed to setup database tables!") 
     457            raise rrdbot_error("Failed to setup database tables!") 
    388458 
    389459        return service_id 
     
    392462def ccs_init(): 
    393463    registerService(ccs_rrdbot) 
     464    #Ensure Certificates exist 
     465    ca = ccs_ca() 
     466    ca.ensureCertificateExists("rrdbot") 
     467    #Ensure state is set to 0 
     468    session = getSessionE(ADMIN_SESSION_ID) 
     469    sql = "UPDATE snmp_state SET state=0" 
     470    session.execute(sql, ())     
Note: See TracChangeset for help on using the changeset viewer.