summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
authorAdrian Likins <alikins@redhat.com>2007-09-27 13:47:50 -0400
committerAdrian Likins <alikins@redhat.com>2007-09-27 13:47:50 -0400
commit064afab85ea8ce7df11ad0e4b92eab8b431c90e3 (patch)
treedb5281c14ece624553b8d8061dfa07f941a8a881 /func
parent72f973619e507a240359ed87c6f3597ed8bf22b4 (diff)
downloadthird_party-func-064afab85ea8ce7df11ad0e4b92eab8b431c90e3.tar.gz
third_party-func-064afab85ea8ce7df11ad0e4b92eab8b431c90e3.tar.xz
third_party-func-064afab85ea8ce7df11ad0e4b92eab8b431c90e3.zip
move logger and config_data to func/func
update modules that need new location modules/func_module.py: update to use new logger/config locations, also go ahead and register as a real module, to shut up the start up. It shouldn't hurt anything Some minor import reordering at a couple places (I try to keep at least system import alphabetical)
Diffstat (limited to 'func')
-rwxr-xr-xfunc/config_data.py52
-rwxr-xr-xfunc/logger.py83
2 files changed, 135 insertions, 0 deletions
diff --git a/func/config_data.py b/func/config_data.py
new file mode 100755
index 0000000..daa366a
--- /dev/null
+++ b/func/config_data.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+# func
+#
+# Copyright 2006, Red Hat, Inc
+# see AUTHORS
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import codes
+
+import os
+import ConfigParser
+
+CONFIG_FILE = "/etc/func/minion.conf"
+
+class Config:
+
+ # this class is a Borg
+ __shared_state = {}
+ has_read = False
+ ds = {}
+
+ def __init__(self):
+ self.__dict__ = self.__shared_state
+ if not self.has_read:
+ self.read()
+ Config.has_read = True
+
+ def read(self):
+
+ if not os.path.exists(CONFIG_FILE):
+ raise codes.FuncException("Missing %s" % CONFIG_FILE)
+
+ cp = ConfigParser.ConfigParser()
+
+ cp.read([CONFIG_FILE])
+
+ self.ds["log_level"] = cp.get("general","log_level")
+ self.ds["overlord_server"] = cp.get("general","overlord_server")
+ self.ds["certmaster"] = cp.get("general", "certmaster")
+ self.ds["cert_dir"] = cp.get("general", "cert_dir")
+
+ def get(self):
+ return self.ds
+
+
diff --git a/func/logger.py b/func/logger.py
new file mode 100755
index 0000000..f6f9c0f
--- /dev/null
+++ b/func/logger.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+
+## func
+##
+## Copyright 2007, Red Hat, Inc
+## See AUTHORS
+##
+## This software may be freely redistributed under the terms of the GNU
+## general public license.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+##
+##
+
+
+import logging
+import config_data
+
+
+# from the comments in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
+class Singleton(object):
+ def __new__(type, *args, **kwargs):
+ if not '_the_instance' in type.__dict__:
+ type._the_instance = object.__new__(type, *args, **kwargs)
+ return type._the_instance
+
+# logging is weird, we don't want to setup multiple handlers
+# so make sure we do that mess only once
+
+class Logger(Singleton):
+ _no_handlers = True
+
+ def __init__(self, logfilepath ="/var/log/func/func.log"):
+
+ self.config = config_data.Config().get()
+ if self.config.has_key("log_level"):
+ self.loglevel = logging._levelNames[self.config["log_level"]]
+ else:
+ self.loglevel = logging.INFO
+ self._setup_logging()
+ if self._no_handlers:
+ self._setup_handlers(logfilepath=logfilepath)
+
+ def _setup_logging(self):
+ self.logger = logging.getLogger("svc")
+
+ def _setup_handlers(self, logfilepath="/var/log/func/func.log"):
+ handler = logging.FileHandler(logfilepath, "a")
+ self.logger.setLevel(self.loglevel)
+ formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
+ handler.setFormatter(formatter)
+ self.logger.addHandler(handler)
+ self._no_handlers = False
+
+
+class AuditLogger(Singleton):
+ _no_handlers = True
+ def __init__(self, logfilepath = "/var/log/func/audit.log"):
+ self.loglevel = logging.INFO
+ self._setup_logging()
+ if self._no_handlers:
+ self._setup_handlers(logfilepath=logfilepath)
+
+ def log_call(self, CN, cert_hash, method, params):
+ # square away a good parseable format at some point -akl
+ self.logger.info("%s %s %s called with %s" % (CN, cert_hash, method, params))
+
+
+ def _setup_logging(self):
+ self.logger = logging.getLogger("audit")
+
+ def _setup_handlers(self, logfilepath="/var/log/func/audit.log"):
+ handler = logging.FileHandler(logfilepath, "a")
+ self.logger.setLevel(self.loglevel)
+ formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
+ handler.setFormatter(formatter)
+ self.logger.addHandler(handler)
+ self._no_handlers = False
+
+
+