From f2980f917851c8c6512ecd7afac6e3a981c5f707 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Mon, 11 Oct 2021 23:43:50 +0200 Subject: [PATCH] sysutils/puppet-agent: add log file --- sysutils/puppet-agent/pkg-descr | 12 +++++ .../models/OPNsense/PuppetAgent/Menu/Menu.xml | 5 +- .../OPNsense/PuppetAgent/PuppetAgent.xml | 5 +- .../systemhealth/logformats/puppet_agent.py | 50 +++++++++++++++++++ .../templates/OPNsense/PuppetAgent/+TARGETS | 1 + .../OPNsense/PuppetAgent/newsyslog.conf | 4 ++ .../OPNsense/PuppetAgent/puppetagent.conf | 1 + 7 files changed, 74 insertions(+), 4 deletions(-) create mode 100755 sysutils/puppet-agent/src/opnsense/scripts/systemhealth/logformats/puppet_agent.py create mode 100644 sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/newsyslog.conf diff --git a/sysutils/puppet-agent/pkg-descr b/sysutils/puppet-agent/pkg-descr index ed7736616..959369790 100644 --- a/sysutils/puppet-agent/pkg-descr +++ b/sysutils/puppet-agent/pkg-descr @@ -5,3 +5,15 @@ hosts, along with obviously discrete elements like packages, services, and files. WWW: https://puppet.com/docs/puppet/latest/man/agent.html + +Plugin Changelog +================ + +1.0 + +Added: +* add log file + +0.1 + +* Initial release diff --git a/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/Menu/Menu.xml b/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/Menu/Menu.xml index e0c6f69d7..d989bfc18 100644 --- a/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/Menu/Menu.xml +++ b/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/Menu/Menu.xml @@ -1,5 +1,8 @@ - + + + + diff --git a/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/PuppetAgent.xml b/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/PuppetAgent.xml index 100aeeeb0..f706d65a5 100644 --- a/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/PuppetAgent.xml +++ b/sysutils/puppet-agent/src/opnsense/mvc/app/models/OPNsense/PuppetAgent/PuppetAgent.xml @@ -1,8 +1,7 @@ //OPNsense/puppetagent - - Manage Puppet Agent service - + 1.0.0 + Manage Puppet Agent service diff --git a/sysutils/puppet-agent/src/opnsense/scripts/systemhealth/logformats/puppet_agent.py b/sysutils/puppet-agent/src/opnsense/scripts/systemhealth/logformats/puppet_agent.py new file mode 100755 index 000000000..a4013e9ed --- /dev/null +++ b/sysutils/puppet-agent/src/opnsense/scripts/systemhealth/logformats/puppet_agent.py @@ -0,0 +1,50 @@ +""" + Copyright (c) 2021 Frank Wall + Copyright (c) 2020 Ad Schellevis + Copyright (c) 2020 devNan0 + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +""" +import re +import datetime +from . import BaseLogFormat +puppet_timeformat = r'^(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+[-+]{1}\d{4}).*' + + +class TelegrafLogFormat(BaseLogFormat): + def __init__(self, filename): + super(TelegrafLogFormat, self).__init__(filename) + self._priority = 100 + + def match(self, line): + return self._filename.find('puppet') > -1 and re.match(puppet_timeformat, line) is not None + + @staticmethod + def timestamp(line): + tmp = re.match(puppet_timeformat, line) + grp = tmp.group(1) + return datetime.datetime.strptime(grp, "%Y-%m-%d %H:%M:%S %z").isoformat() + + @staticmethod + def line(line): + return line[26:].strip() diff --git a/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/+TARGETS b/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/+TARGETS index 085fa8c75..c34b302bb 100644 --- a/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/+TARGETS +++ b/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/+TARGETS @@ -1,2 +1,3 @@ puppetagent.conf:/usr/local/etc/puppet/puppet.conf +newsyslog.conf:/etc/newsyslog.conf.d/puppet-agent rc.conf.d:/etc/rc.conf.d/puppet diff --git a/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/newsyslog.conf b/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/newsyslog.conf new file mode 100644 index 000000000..190ea6a8f --- /dev/null +++ b/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/newsyslog.conf @@ -0,0 +1,4 @@ +{% if helpers.exists('OPNsense.puppetagent.general') and OPNsense.puppetagent.general.Enabled|default("0") == "1" %} +# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] +/var/log/puppet-agent.log puppet:puppet 640 7 * @T00 JCB /var/run/puppet/agent.pid 1 +{% endif %} diff --git a/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/puppetagent.conf b/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/puppetagent.conf index 3da8f402e..c375941a9 100644 --- a/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/puppetagent.conf +++ b/sysutils/puppet-agent/src/opnsense/service/templates/OPNsense/PuppetAgent/puppetagent.conf @@ -2,6 +2,7 @@ [main] certname = {{ system.hostname|lower }}.{{ system.domain|lower }} server = {{ OPNsense.puppetagent.general.FQDN|default("") }} +logdest = /var/log/puppet-agent.log {% if helpers.exists('OPNsense.puppetagent.general') and not helpers.empty('OPNsense.puppetagent.general.Environment') %} [agent] environment = {{ OPNsense.puppetagent.general.Environment|default("") }}