[ add comment ] ( 6 views ) | [ 0 trackbacks ] | permalink
#!/usr/bin/python
__version__ = "0.7"
__author__ = "nej"
__descr__ = "realtime conversion of Oracle DBID to DBNAME"
import os
import sys
import re
import traceback
import datetime
import socket
import signal
from time import sleep
""" globals """
DBLIST = ( "/opt/oracle/dbid1.txt", "/opt/oracle/dbid2.txt" )
LOGPATH = "/var/log/clc/%s/oracle/"
ERRPATH = "/var/log/clc/%s/oracle/error/"
FIFONAME = "/opt/oracle/syslog.pipe"
classmap = {}
errfd = None
re_host = re.compile(".*(mycz[^ \.]*).*")
re_dbid = re.compile(".*DBID:\[\d+\] .([0-9]*).*")
def _quit(signum, frame):
""" gracefully quit on signal """
for item in classmap:
print "closing %s" %classmap[item].host
classmap[item].fd.close()
err = "* program closes because signal %s sent" %signum
errfd.write("%s\n" % err)
errfd.close()
sys.exit(0)
""" hostbased database information put in class """
class dbHost(object):
def __init__(self, host):
self.dbdict = {}
self.host = host
self.dt = datetime.date.today()
self.logpath = LOGPATH %( self.dt )
if not os.path.exists( "%s" %self.logpath ):
os.makedirs( "%s" %self.logpath )
self.logfilename = "%s-oracle" %host
self.log = self.logpath + self.logfilename
self.fd = open(self.log, "a")
def __repr__(self):
return self.host
def write(self, data):
self.fd.write("%s\n" % data)
self.fd.flush()
def classmap_init(server, dbid, dbname):
""" key: value mapping """
try:
classmap[server]
except KeyError:
classmap.update({server: dbHost(server)})
try:
classmap[server].dbdict[dbid]
except KeyError:
classmap[server].dbdict.update({dbid: dbname})
def io_processor(input):
""" reads input line, parses out hostname and dbid
appends dbid at eol """
ok_flag = True
""" can we extract host? """
try:
host = (re_host.search(input)).groups()[0]
except AttributeError:
""" a line has no servername match """
err = "* a line has no servername match ^%s" %input
errfd.write("%s\n" % err)
ok_flag = False
""" can we extract dbid? """
try:
dbid = (re_dbid.search(input)).groups()[0]
except AttributeError:
""" a line has no dbid match """
err = "* a line has no dbid match ^%s" %input
errfd.write("%s\n" % err)
ok_flag = False
if ok_flag:
try:
classmap[host].write('%s INSTANCENAME:[%s] \'%s\'' %(input[:-1], \
len(classmap[host].dbdict[dbid]), classmap[host].dbdict[dbid]))
except KeyError:
""" no record in class for given servername or dbid """
err = "* no record in class for given servername or dbid ( host: %s, dbid: %s ) ^%s" \
%( host, dbid, input )
errfd.write("%s\n" % err)
def pipe_read():
""" read from standard input and on any external exception
close all fd and exit """
fd = open(FIFONAME, 'r')
while 1:
line = "%s" %( fd.readline() )
if line:
io_processor(line)
def init():
""" this function loads database conversion table DBLIST
and creates class instance for each host
the syntax of the file is as follows:
HOST_NAME;FQDN;DBID;INSTANCE_NAME;DB_NAME;DB_UNIQUE_NAME;COLLECTION_TIMESTAMP
0 1 2 3 4 5 6
we use fields 1,2,3
"""
""" prepare error file / log file """
global errfd
errpath = ERRPATH %( datetime.date.today() )
if not os.path.exists( "%s" %errpath ):
os.makedirs( "%s" %errpath )
errfd = open(errpath + "error.log", "a")
print "error file descriptor: %s" %(errfd)
""" load the data in """
err = "* program restarts, loading conversion tables"
errfd.write("%s\n" % err)
for db_definition in DBLIST:
err = "* reading definition file: %s" % db_definition
errfd.write("%s\n" % err)
for dbdata in open( db_definition, "r" ).readlines():
dbdata = dbdata.split(";")
#dbdata[1] = socket.getfqdn(dbdata[1])
dbdata[1] = dbdata[1].split(".")[0]
try:
err = "* adding dbname: %s ( host: %s, dbid: %s )" \
%( dbdata[3], dbdata[1], dbdata[2] )
errfd.write("%s\n" % err)
classmap_init( dbdata[1], dbdata[2], dbdata[3] )
except:
traceback.print_exc()
pass
if __name__ == "__main__":
signal.signal(signal.SIGTERM, _quit) # kill <program>
signal.signal(signal.SIGINT, _quit) # KeyboardInterrupt
if not os.path.exists(FIFONAME):
os.mkfifo(FIFONAME)
init()
pipe_read()
[ add comment ] ( 8 views ) | [ 0 trackbacks ] | permalink | related link
try:
...
except Exception, e:
print e
import traceback
try:
...
except Exception, e:
traceback.print_exc()
[ add comment ] ( 5 views ) | [ 0 trackbacks ] | permalink | related link
[ add comment ] ( 6 views ) | [ 0 trackbacks ] | permalink
[ add comment ] ( 7 views ) | [ 0 trackbacks ] | permalink
[ add comment ] ( 6 views ) | [ 0 trackbacks ] | permalink | related link
Here at OpenCog, we're creating an open source Artificial General Intelligence framework, intended to one day express general intelligence at the human level and beyond.
the guy behind this is either genius or a crook.
[ add comment ] ( 6 views ) | [ 0 trackbacks ] | permalink | related link
Gephi is an interactive visualization and exploration platform for all kinds of networks and complex systems, dynamic and hierarchical graphs.
Runs on Windows, Linux and Mac OS X. Gephi is open-source and free.
[ add comment ] ( 6 views ) | [ 0 trackbacks ] | permalink | related link
WebGL (Web Graphics Library) je JavaScriptové API pro nativní zobrazování (bez použití zásuvných modulů) interaktivní 3D grafiky. WebGL programy se skládají z obslužného kódu napsaného v JavaScriptu a kódu shaderu, který je vykonáván na grafické kartě počítače. WebGL je vyvíjeno a spravováno neziskovou organizací Khronos Group[1].
[ add comment ] ( 6 views ) | [ 0 trackbacks ] | permalink | related link
Justin Windle has just released a new physics engine called CoffeePhysics, which as it’s name states, is written in CoffeeScript. It is quite lightweight (minified, it’s just 8KB), but also very powerful. http://badassjs.com/post/18503583619/co ... written-in
[ add comment ] ( 5 views ) | [ 0 trackbacks ] | permalink | related link