Changeset 1284
- Timestamp:
- 01/12/07 17:12:47 (6 years ago)
- Location:
- ccsd/trunk/crcnetd/modules
- Files:
-
- 2 edited
-
ccs_graph.py (modified) (6 diffs)
-
ccs_rrdbot.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ccsd/trunk/crcnetd/modules/ccs_graph.py
r1269 r1284 25 25 from crcnetd._utils.ccsd_session import getSession, getSessionE 26 26 from crcnetd._utils.ccsd_server import exportViaXMLRPC 27 from crcnetd._utils.ccsd_service import ccsd_service, ccs_service_error, \ 28 registerService 29 27 from crcnetd._utils.ccsd_service import getServiceInstance 30 28 ccs_mod_type = CCSD_SERVER 29 GRAPH_SERVER = "localhost:80" 31 30 32 31 @exportViaXMLRPC(SESSION_RO, AUTH_USER) … … 134 133 @exportViaXMLRPC(SESSION_RO, AUTH_USER) 135 134 def getGraphs(session_id, host_id=-1, group_id=-1, mirror='f'): 135 global GRAPH_SERVER 136 136 '''This returns data to draw graphs''' 137 137 … … 183 183 graphs2.append(newgraph) 184 184 185 return graphs2185 return GRAPH_SERVER, graphs2 186 186 187 187 @exportViaXMLRPC(SESSION_RO, AUTH_USER) … … 223 223 if host_id == '' and len(hostList2) > 0: 224 224 host_id = hostList2[0]["host_id"] 225 elif host_id == '': 226 host_id = 0 225 227 226 228 linkGraphs = getLinkGraphs(session_id) … … 238 240 newgraph ["group_name"] = graph["group_name"] 239 241 hostGraphs2.append(newgraph) 240 graphs = getGraphs(session_id)242 server, graphs = getGraphs(session_id) 241 243 times = getTimes(session_id) 242 244 pack = [hostList2, linkGraphs2, hostGraphs2, graphs, times] … … 429 431 res = session.execute(sql, (group_id)) 430 432 return 1 433 434 def 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 26 26 from crcnetd._utils.ccsd_server import exportViaXMLRPC 27 27 from crcnetd._utils.ccsd_service import ccsd_service, ccs_service_error, \ 28 registerService 29 28 registerService, getServiceInstance 29 from crcnetd._utils.ccsd_cfengine import ccs_revision 30 from crcnetd._utils.ccsd_ca import * 31 import os.path 30 32 import time 33 import shutil 31 34 32 35 ccs_mod_type = CCSD_SERVER 33 36 37 class rrdbot_error(ccs_service_error): 38 pass 39 34 40 @exportViaXMLRPC(SESSION_RW, AUTH_USER) 35 41 def snmp_found(session_id, hostname, classname, number, data=''): … … 63 69 return 1 64 70 71 @catchEvent("interfaceAdded") 72 def interfaceAdded(eventName, host_id, session_id, **params): 73 addSnmpInstruction(session_id, host_id, 3, None, None, None) 74 65 75 @exportViaXMLRPC(SESSION_RW, AUTH_USER) 66 76 def addSnmpInstruction(session_id, host_id, instr, param1=None, param2=None, param3=None): … … 89 99 def setSnmpState(session_id,state): 90 100 '''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 97 114 else: 98 return 0115 return 1 99 116 100 117 @exportViaXMLRPC(SESSION_RO, AUTH_USER) … … 168 185 sql = "UPDATE rrdbot_class SET depends=0, poll=\'%s%s\' WHERE class_id=%%s" % (clas["poll"], ":exist") 169 186 res2 = session.execute(sql, (clas["class_id"])) 170 print sql171 print clas["class_id"]172 187 173 188 # Delete the class and its class parts … … 323 338 return 1 324 339 340 341 @catchEvent("revisionPrepared") 342 def 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 325 380 class ccs_rrdbot(ccsd_service): 326 381 … … 331 386 # Call base class setup 332 387 ccsd_service.__init__(self, session_id, service_id) 333 334 388 335 389 def getNetworkTemplateVariables(self): … … 356 410 classes[clas["class_id"]]["subs"] = [] 357 411 358 359 412 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") 360 419 return variables 361 420 421 422 362 423 @staticmethod 363 424 def initialiseService(): … … 370 431 session.begin("initialising rrdbot service") 371 432 try: 433 372 434 373 435 session.execute("INSERT INTO service (service_id, service_name, " \ … … 376 438 service_id = session.getCountOf("SELECT currval('" \ 377 439 "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), ()) 378 448 379 449 # Commit the changeset … … 385 455 log_error("Unable to initialise rrdbot database entries!", \ 386 456 sys.exc_info()) 387 raise quagga_error("Failed to setup database tables!")457 raise rrdbot_error("Failed to setup database tables!") 388 458 389 459 return service_id … … 392 462 def ccs_init(): 393 463 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.
