Merge pull request #2571 from fraenki/puppet_100

sysutils/puppet-agent: additions for release 1.0
This commit is contained in:
Frank Wall
2021-10-12 11:18:50 +02:00
committed by GitHub
8 changed files with 111 additions and 19 deletions
+13
View File
@@ -5,3 +5,16 @@ 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
* add introduction page
0.1
* Initial release
@@ -1,5 +1,8 @@
<menu>
<Services>
<PuppetAgent VisibleName="Puppet Agent" url="/ui/puppetagent"/>
<PuppetAgent VisibleName="Puppet Agent" cssClass="fa fa-certificate fa-fw">
<Settings order="10" url="/ui/puppetagent"/>
<Logs order="20" url="/ui/diagnostics/log/core/puppet-agent"/>
</PuppetAgent>
</Services>
</menu>
@@ -1,8 +1,7 @@
<model>
<mount>//OPNsense/puppetagent</mount>
<description>
Manage Puppet Agent service
</description>
<version>1.0.0</version>
<description>Manage Puppet Agent service</description>
<items>
<!-- container -->
<general>
@@ -1,5 +1,6 @@
{#
OPNsense® is Copyright © 2021 Frank Wall
OPNsense® is Copyright © 2021 Jan Winkler
OPNsense® is Copyright © 2014 2015 by Deciso B.V.
All rights reserved.
@@ -47,20 +48,40 @@ POSSIBILITY OF SUCH DAMAGE.
});
</script>
<div class="alert alert-info hidden" role="alert" id="responseMsg">
<ul class="nav nav-tabs" role="tablist" id="maintabs">
<li class="active"><a data-toggle="tab" id="settings-introduction" href="#subtab_settings-introduction"><b>{{ lang._('Introduction') }}</b></a></li>
<li><a data-toggle="tab" id="settings-tab" href="#settings"><b>{{ lang._('Settings') }}</b></a></li>
</ul>
<div class="content-box tab-content">
<div id="subtab_settings-introduction" class="tab-pane fade in active">
<div class="col-md-12">
<h1>{{ lang._('Quick Start Guide') }}</h1>
<p>{{ lang._("Welcome to the Puppet Agent plugin! This plugin allows you to integrate OPNsense with your Puppet environment.") }}</p>
<p>{{ lang._("Keep in mind that you should not treat OPNsense like any other operating system. Most notably you should not modify system files or packages. Instead use the OPNsense API to make configuration changes and to manage plugins. The following tools are a good starting point when trying to automate OPNsense with Puppet:") }}</p>
<ul>
<li>{{ lang._("%sopn-cli:%s A command line client to configure OPNsense core and plugin components through their respective APIs.") | format('<a href="https://github.com/andeman/opn-cli" target="_blank">', '</a>') }}</li>
<li>{{ lang._("%spuppet/opnsense:%s A read-to-use Puppet module for automating the OPNsense firewall.") | format('<a href="https://github.com/andeman/puppet-opnsense" target="_blank">', '</a>') }}</li>
</ul>
<p>{{ lang._("Note that these tools are not directly related to this plugin. Please report issues and missing features directly to the author.") }}</p>
</div>
</div>
<div id="settings" class="tab-pane fade">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_GeneralSettings'])}}
<div class="col-md-12">
<hr/>
<button class="btn btn-primary" id="saveAct"
data-endpoint='/api/puppetagent/service/reconfigure'
data-label="{{ lang._('Save') }}"
data-service-widget="puppetagent"
data-error-title="{{ lang._('Error reconfiguring puppetagent') }}"
type="button">
</button>
<br/>
</div>
</div>
</div>
<div class="col-md-12">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_GeneralSettings'])}}
</div>
<div class="col-md-12">
<button class="btn btn-primary" id="saveAct"
data-endpoint='/api/puppetagent/service/reconfigure'
data-label="{{ lang._('Save') }}"
data-service-widget="puppetagent"
data-error-title="{{ lang._('Error reconfiguring puppetagent') }}"
type="button"
></button>
</div>
@@ -0,0 +1,50 @@
"""
Copyright (c) 2021 Frank Wall
Copyright (c) 2020 Ad Schellevis <ad@opnsense.org>
Copyright (c) 2020 devNan0 <nan0@nan0.dev>
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 PuppetLogFormat(BaseLogFormat):
def __init__(self, filename):
super(PuppetLogFormat, 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()
@@ -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
@@ -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 %}
@@ -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("") }}