summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-07-09 01:56:22 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-07-09 01:56:22 +0000
commit7c9205aafd495ae053b899ad900cdd40913566a2 (patch)
tree33d895f0f10d24d9a1a13a207109a9adf1f94857 /src
parent105b32dd22956e22b3800c43814a2a57bc5cbd8c (diff)
downloadbcfg2-7c9205aafd495ae053b899ad900cdd40913566a2.tar.gz
bcfg2-7c9205aafd495ae053b899ad900cdd40913566a2.tar.bz2
bcfg2-7c9205aafd495ae053b899ad900cdd40913566a2.zip
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 <hostname> -p <profile> -g <grouplist> 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
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Plugins/Trigger.py33
-rw-r--r--src/lib/Server/Plugins/__init__.py2
2 files changed, 34 insertions, 1 deletions
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']