Index: /trunk/jobarchived/jobarchived.conf
===================================================================
--- /trunk/jobarchived/jobarchived.conf	(revision 214)
+++ /trunk/jobarchived/jobarchived.conf	(revision 214)
@@ -0,0 +1,13 @@
+[DEFAULT]
+DAEMONIZE			: 1
+DEBUG_LEVEL			: 1
+USE_SYSLOG			: 1
+SYSLOG_LEVEL			: 0
+SYSLOG_FACILITY			: DAEMON
+GMETAD_CONF			: /etc/gmetad.conf
+ARCHIVE_XMLSOURCE		: localhost:8651
+ARCHIVE_DATASOURCES		: "LISA Cluster"
+ARCHIVE_HOURS_PER_RRD		: 12
+ARCHIVE_EXCLUDE_METRICS		: "^Temp_.*_.*", ".*_Temp_.*", ".*_RPM_.*", ".*_Battery_.*"
+ARCHIVE_PATH			: /data/jobarch/rrds
+JOB_SQL_DBASE			: localhost/jobarch
Index: /trunk/jobarchived/jobarchived.py
===================================================================
--- /trunk/jobarchived/jobarchived.py	(revision 213)
+++ /trunk/jobarchived/jobarchived.py	(revision 214)
@@ -1,96 +1,159 @@
 #!/usr/bin/env python
 
-import xml.sax
-import xml.sax.handler
-import socket
-import sys
-import syslog
-import string
-import os
-import os.path
-import time
-import thread
-import threading
-import random
-import re
-from types import *
-import DBClass
-
-# Specify debugging level here (only when _not_ DAEMONIZE)
-#
-# 11 = XML: metrics
-# 10 = XML: host, cluster, grid, ganglia
-# 9  = RRD activity, gmetad config parsing
-# 8  = RRD file activity
-# 6  = SQL
-# 1  = daemon threading
-# 0  = errors
-#
-# default: 0
-DEBUG_LEVEL = 1
-
-# Enable logging to syslog?
-#
-USE_SYSLOG = 1
-
-# What level msg'es should be logged to syslog?
-#
-# default: lvl 0 (errors)
-#
-SYSLOG_LEVEL = 0
-
-# Which facility to use in syslog
-#
-# Syntax I.e.:
-# 	LOG_KERN, LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_LPR, 
-# 	LOG_NEWS, LOG_UUCP, LOG_CRON and LOG_LOCAL0 to LOG_LOCAL7
-#
-SYSLOG_FACILITY = syslog.LOG_DAEMON
-
-# Where is the gmetad.conf located
-#
-GMETAD_CONF = '/etc/gmetad.conf'
-
-# Where to grab XML data from
-# Normally: local gmetad (port 8651)
-#
-# Syntax: <hostname>:<port>
-#
-ARCHIVE_XMLSOURCE = "localhost:8651"
-
-# List of data_source names to archive for
-#
-# Syntax: [ "<clustername>", "<clustername>" ]
-#
-ARCHIVE_DATASOURCES = [ "LISA Cluster", "LISA Test Cluster" ]
-
-# Where to store the archived rrd's
-#
-ARCHIVE_PATH = '/data/toga/rrds'
-
-# Amount of hours to store in one single archived .rrd
-#
-ARCHIVE_HOURS_PER_RRD = 12
-
-# Which metrics to exclude from archiving
-# NOTE: This can be a regexp or a string
-#
-ARCHIVE_EXCLUDE_METRICS = [ "^Temp_.*_.*", ".*_Temp_.*", ".*_RPM_.*", ".*_Battery_.*" ]
-
-# Toga's SQL dbase to use
-#
-# Syntax: <hostname>/<database>
-#
-TOGA_SQL_DBASE = "localhost/toga"
-
-# Wether or not to run as a daemon in background
-#
-DAEMONIZE = 1
-
-######################
-#                    #
-# Configuration ends #
-#                    #
-######################
+import getopt, syslog, ConfigParser, sys
+
+def processArgs( args ):
+
+        SHORT_L = 'c:'
+        LONG_L = 'config='
+
+        config_filename = None
+
+        try:
+
+                opts, args = getopt.getopt( args, SHORT_L, LONG_L )
+
+        except getopt.error, detail:
+
+                print detail
+                sys.exit(1)
+
+        for opt, value in opts:
+
+                if opt in [ '--config', '-c' ]:
+
+                        config_filename = value
+
+        if not config_filename:
+
+                config_filename = '/etc/jobarchived.conf'
+
+	try:
+		return loadConfig( config_filename )
+
+	except ConfigParser.NoOptionError, detail:
+
+		print detail
+		sys.exit( 1 )
+
+def loadConfig( filename ):
+
+	def getlist( cfg_string ):
+
+		my_list = [ ]
+
+		for item_txt in cfg_string.split( ',' ):
+
+			sep_char = None
+
+			item_txt = item_txt.strip()
+
+			for s_char in [ "'", '"' ]:
+
+				if item_txt.find( s_char ) != -1:
+
+					if item_txt.count( s_char ) != 2:
+
+						print 'Missing quote: %s' %item_txt
+						sys.exit( 1 )
+
+					else:
+
+						sep_char = s_char
+						break
+
+			if sep_char:
+
+				item_txt = item_txt.split( sep_char )[1]
+
+			my_list.append( item_txt )
+
+		return my_list
+
+	cfg = ConfigParser.ConfigParser()
+
+	cfg.read( filename )
+
+	# Which metrics to exclude from archiving
+	global DEBUG_LEVEL, USE_SYSLOG, SYSLOG_LEVEL, SYSLOG_FACILITY, GMETAD_CONF, ARCHIVE_XMLSOURCE, ARCHIVE_DATASOURCES, ARCHIVE_PATH, ARCHIVE_HOURS_PER_RRD, ARCHIVE_EXCLUDE_METRICS, JOB_SQL_DBASE, DAEMONIZE
+
+	# Where to store the archived rrd's
+	#
+	ARCHIVE_PATH = cfg.get( 'DEFAULT', 'ARCHIVE_PATH' )
+
+	# Amount of hours to store in one single archived .rrd
+	#
+	ARCHIVE_HOURS_PER_RRD = cfg.getint( 'DEFAULT', 'ARCHIVE_HOURS_PER_RRD' )
+
+	# Specify debugging level here (only when _not_ DAEMONIZE)
+	#
+	# 11 = XML: metrics
+	# 10 = XML: host, cluster, grid, ganglia
+	# 9  = RRD activity, gmetad config parsing
+	# 8  = RRD file activity
+	# 6  = SQL
+	# 1  = daemon threading
+	# 0  = errors
+	#
+	# default: 0
+	DEBUG_LEVEL = cfg.getint( 'DEFAULT', 'DEBUG_LEVEL' )
+
+	# Enable logging to syslog?
+	#
+	USE_SYSLOG = cfg.getboolean( 'DEFAULT', 'USE_SYSLOG' )
+
+	# What level msg'es should be logged to syslog?
+	#
+	# default: lvl 0 (errors)
+	#
+	SYSLOG_LEVEL = cfg.getint( 'DEFAULT', 'SYSLOG_LEVEL' )
+
+	# Which facility to use in syslog
+	#
+	# Syntax I.e.:
+	# 	LOG_KERN, LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_LPR, 
+	# 	LOG_NEWS, LOG_UUCP, LOG_CRON and LOG_LOCAL0 to LOG_LOCAL7
+	#
+	try:
+
+		SYSLOG_FACILITY = eval( 'syslog.LOG_' + cfg.get( 'DEFAULT', 'SYSLOG_FACILITY' ) )
+
+	except AttributeError, detail:
+
+		print 'Unknown syslog facility'
+		sys.exit( 1 )
+
+	# Where is the gmetad.conf located
+	#
+	GMETAD_CONF = cfg.get( 'DEFAULT', 'GMETAD_CONF' )
+
+	# Where to grab XML data from
+	# Normally: local gmetad (port 8651)
+	#
+	# Syntax: <hostname>:<port>
+	#
+	ARCHIVE_XMLSOURCE = cfg.get( 'DEFAULT', 'ARCHIVE_XMLSOURCE' )
+
+	# List of data_source names to archive for
+	#
+	# Syntax: [ "<clustername>", "<clustername>" ]
+	#
+        ARCHIVE_DATASOURCES = getlist( cfg.get( 'DEFAULT', 'ARCHIVE_DATASOURCES' ) )
+
+	# NOTE: This can be a regexp or a string
+	#
+	ARCHIVE_EXCLUDE_METRICS = getlist( cfg.get( 'DEFAULT', 'ARCHIVE_EXCLUDE_METRICS' ) )
+
+	# Toga's SQL dbase to use
+	#
+	# Syntax: <hostname>/<database>
+	#
+	JOB_SQL_DBASE = cfg.get( 'DEFAULT', 'JOB_SQL_DBASE' )
+
+	# Wether or not to run as a daemon in background
+	#
+	DAEMONIZE = cfg.getboolean( 'DEFAULT', 'DAEMONIZE' )
+
+	return True
 
 ###
@@ -114,4 +177,9 @@
 This is TOrque-GAnglia's data Daemon
 """
+
+from types import *
+
+import DBClass
+import xml.sax, xml.sax.handler, socket, string, os, os.path, time, thread, threading, random, re
 
 class DataSQLStore:
@@ -438,5 +506,5 @@
 	def __init__( self ):
 
-		self.ds = DataSQLStore( TOGA_SQL_DBASE.split( '/' )[0], TOGA_SQL_DBASE.split( '/' )[1] )
+		self.ds = DataSQLStore( JOB_SQL_DBASE.split( '/' )[0], JOB_SQL_DBASE.split( '/' )[1] )
 		self.jobs_processed = [ ]
 		self.jobs_to_store = [ ]
@@ -1452,4 +1520,7 @@
 	"""Program startup"""
 
+	if not processArgs( sys.argv[1:] ):
+		sys.exit( 1 )
+
 	if( DAEMONIZE and USE_SYSLOG ):
 		syslog.openlog( 'jobarchived', syslog.LOG_NOWAIT, SYSLOG_FACILITY )
