From 7c9205aafd495ae053b899ad900cdd40913566a2 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Thu, 9 Jul 2009 01:56:22 +0000 Subject: Trigger: Add Trigger plugin Implement Trigger plugin. Can be used to call out when clients upload statistics packets. This plugin will call each executable within the Trigger spool directory, passing -p -g The group list is delimited with colons. git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5316 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Plugins/Trigger.py | 33 +++++++++++++++++++++++++++++++++ src/lib/Server/Plugins/__init__.py | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/lib/Server/Plugins/Trigger.py (limited to 'src') diff --git a/src/lib/Server/Plugins/Trigger.py b/src/lib/Server/Plugins/Trigger.py new file mode 100644 index 000000000..d73e143ee --- /dev/null +++ b/src/lib/Server/Plugins/Trigger.py @@ -0,0 +1,33 @@ +import os +import Bcfg2.Server.Plugin + +def async_run(prog, args): + pid = os.fork() + if pid: + os.waitpid(pid, 0) + else: + dpid = os.fork() + if not dpid: + os.system(" ".join([prog] + args)) + os._exit(0) + +class Trigger(Bcfg2.Server.Plugin.Plugin, + Bcfg2.Server.Plugin.Statistics): + name = 'Trigger' + __version__ = '$Id' + + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + Bcfg2.Server.Plugin.Statistics.__init__(self) + try: + os.stat(self.data) + except: + self.logger.error("Trigger: spool directory %s does not exist; unloading" % self.data) + raise Bcfg2.Server.Plugin.PluginInitError + + def process_statistics(self, metadata, _): + args = [metadata.hostname, '-p', metadata.profile, '-g', + ':'.join([g for g in metadata.groups])] + for notifier in os.listdir(self.data): + n = self.data + '/' + notifier + async_run(n, args) diff --git a/src/lib/Server/Plugins/__init__.py b/src/lib/Server/Plugins/__init__.py index 798e395b2..48b6caffb 100644 --- a/src/lib/Server/Plugins/__init__.py +++ b/src/lib/Server/Plugins/__init__.py @@ -4,4 +4,4 @@ __revision__ = '$Revision$' __all__ = ['Account', 'Base', 'Bundler', 'Cfg', 'Decisions', 'GBundler', 'Git', 'Hostbase', 'Metadata', 'NagiosGen', 'Packages', 'Properties', 'Probes', 'Pkgmgr', 'Rules', 'SSHbase', 'Snapshots' 'Statistics', - 'Svcmgr', 'Svn', 'TCheetah', 'SGenshi', 'TGenshi', 'Vhost'] + 'Svcmgr', 'Svn', 'TCheetah', 'Trigger', 'SGenshi', 'TGenshi', 'Vhost'] -- cgit v1.2.3-1-g7c22