From 207af2b6a0b357e7b0ba0ed3046bac5e3dafc9c4 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Dec 2010 10:52:20 +0100 Subject: add fusioninventory-agent-yum-plugin --- fusioninventory-agent.py | 39 ++++++++++++++++++++++++++++++++++++++ fusioninventory-agent.spec | 47 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 fusioninventory-agent.py diff --git a/fusioninventory-agent.py b/fusioninventory-agent.py new file mode 100644 index 0000000..08081d4 --- /dev/null +++ b/fusioninventory-agent.py @@ -0,0 +1,39 @@ +# A plugin for yum which notifies the FusionInventory Agent to send a inventory +# +# Copyright (c) 2010 Remi Collet +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# version 0.1 + +from yum.plugins import TYPE_CORE +from urlgrabber.grabber import urlread +from urlgrabber.grabber import URLGrabError + +requires_api_version = '2.5' +plugin_type = TYPE_CORE + +def posttrans_hook(conduit): + """ + Tell FusionInventory Agent to send an inventory + Run only after an rpm transaction. + """ + try: + res = urlread('http://localhost:62354/now', 2048) + except URLGrabError, e: + conduit.info(4, "Unable to send connect to FusionInventory service") + conduit.info(6, "%s" %(e,)) + return + if res and 'Done.' in res: + conduit.info(2, "FusionInventory agent asked to run an inventory") + else: + conduit.info(4, "Bad anwser from FusionInventory agent") + diff --git a/fusioninventory-agent.spec b/fusioninventory-agent.spec index 3765dd9..f69f7e5 100644 --- a/fusioninventory-agent.spec +++ b/fusioninventory-agent.spec @@ -12,12 +12,13 @@ Release: 2.git%{gitver}%{?dist} # From http://github.com/fusinv/fusioninventory-agent/tarball/master Source0: fusinv-fusioninventory-agent-2.1-48-ga7532c0.tar.gz %else -Release: 1 +Release: 2 Source0: http://search.cpan.org/CPAN/authors/id/F/FU/FUSINV/FusionInventory-Agent-%{version}%{?prever}.tar.gz %endif Source1: %{name}.cron Source2: %{name}.init +Source3: %{name}.py Group: Applications/System License: GPLv2+ @@ -77,7 +78,7 @@ You can add additional packages for optional tasks: * perl-FusionInventory-Agent-Task-SNMPQuery SNMP Query support - +Edit the /etc/sysconfig/%{name} file for service configuration %description -l fr L'agent FusionInventory est une application destinée à aider l'administrateur @@ -96,6 +97,28 @@ Vous pouvez ajouter les paquets additionnels pour les tâches optionnelles : * perl-FusionInventory-Agent-Task-SNMPQuery Gestion de l'interrogation SNMP +Modifier le fichier /etc/sysconfig/%{name} pour configurer le service. + + +%package yum-plugin +Summary: Ask FusionInventory agent to send an inventory when yum exits +Summary(fr): Demande à l'agent FusionInventory l'envoi d'un inventaire +Group: System Environment/Base +BuildRequires: python-devel +Requires: yum >= 3.0 +Requires: %{name} + +%description yum-plugin +fusioninventory-agent-yum-plugin asks the running service agent to send an inventory +when yum exits. + +This requires the service to be running with the --rpc-trust-localhost option. + +%description -l fr yum-plugin +fusioninventory-agent-yum-plugin demande au service de l'agent d'envoyer un +inventaire à la fin de l'exécution de yum. + +Le service doit être actif et lancé avec l'option --rpc-trust-localhost. %prep %if 0%{?gitver:1} @@ -135,8 +158,8 @@ cat </dev/null ';' %{__install} -m 755 -Dp %{SOURCE1} %{buildroot}%{_sysconfdir}/cron.hourly/%{name} %{__install} -m 755 -Dp %{SOURCE2} %{buildroot}%{_initrddir}/%{name} +# Yum plugin +%{__install} -m 644 -D %{SOURCE3} %{buildroot}/usr/lib/yum-plugins/%{name}.py +%{__mkdir_p} %{buildroot}%{_sysconfdir}/yum/pluginconf.d +cat <%{buildroot}%{_sysconfdir}/yum/pluginconf.d/%{name}.conf +[main] +enabled=1 +EOF + %check make test @@ -233,8 +264,16 @@ exit 0 %dir %{_localstatedir}/log/%{name} %dir %{_localstatedir}/lib/%{name} +%files yum-plugin +%defattr(-, root, root) +%config(noreplace) %{_sysconfdir}/yum/pluginconf.d/%{name}.conf +/usr/lib/yum-plugins/%{name}.* + %changelog +* Thu Dec 30 2010 Remi Collet 2.1.7-2 +- add the yum-plugin sub-package + * Mon Dec 13 2010 Remi Collet 2.1.7-1 - update to 2.1.7 http://cpansearch.perl.org/src/FUSINV/FusionInventory-Agent-2.1.7/Changes -- cgit