Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/chrony: add diagnostics #2220

Merged
merged 11 commits into from
Apr 10, 2021
3 changes: 1 addition & 2 deletions net/chrony/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
PLUGIN_NAME= chrony
PLUGIN_VERSION= 1.1
PLUGIN_REVISION= 1
PLUGIN_VERSION= 1.2
PLUGIN_COMMENT= Chrony time synchronisation
PLUGIN_DEPENDS= chrony
PLUGIN_MAINTAINER= m.muenz@gmail.com
Expand Down
4 changes: 4 additions & 0 deletions net/chrony/pkg-descr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ better in virtual environments.
Plugin Changelog
----------------

1.2

* Add Diagnostics

1.1

* Add NTS support
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (C) 2020 Michael Muenz <m.muenz@gmail.com>
* Copyright (C) 2020-2021 Michael Muenz <m.muenz@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,11 +29,57 @@
namespace OPNsense\Chrony\Api;

use OPNsense\Base\ApiMutableServiceControllerBase;
use OPNsense\Core\Backend;
use OPNsense\Chrony\General;

class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\OPNsense\Chrony\General';
protected static $internalServiceTemplate = 'OPNsense/Chrony';
protected static $internalServiceEnabled = 'enabled';
protected static $internalServiceName = 'chrony';

/**
* show chrony sources
* @return array
*/
public function chronysourcesAction()
{
$backend = new Backend();
$response = $backend->configdRun("chrony chronysources");
return array("response" => $response);
}

/**
* show chrony stats
* @return array
*/
public function chronysourcestatsAction()
{
$backend = new Backend();
$response = $backend->configdRun("chrony chronysourcestats");
return array("response" => $response);
}

/**
* show chrony tracking
* @return array
*/
public function chronytrackingAction()
{
$backend = new Backend();
$response = $backend->configdRun("chrony chronytracking");
return array("response" => $response);
}

/**
* show chrony authdata
* @return array
*/
public function chronyauthdataAction()
{
$backend = new Backend();
$response = $backend->configdRun("chrony chronyauthdata");
return array("response" => $response);
}
}
71 changes: 64 additions & 7 deletions net/chrony/src/opnsense/mvc/app/views/OPNsense/Chrony/general.volt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{#
# Copyright (c) 2019 Deciso B.V.
# Copyright (c) 2020 Michael Muenz <m.muenz@gmail.com>
# Copyright (c) 2020-2021 Michael Muenz <m.muenz@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
Expand All @@ -25,24 +25,81 @@
# POSSIBILITY OF SUCH DAMAGE.
#}

<div class="content-box" style="padding-bottom: 1.5em;">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}}
<div class="col-md-12">
<hr />
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_progress"></i></button>
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
<li><a data-toggle="tab" href="#chronysources">{{ lang._('Sources') }}</a></li>
<li><a data-toggle="tab" href="#chronysourcestats">{{ lang._('Source Stats') }}</a></li>
<li><a data-toggle="tab" href="#chronytracking">{{ lang._('Tracking') }}</a></li>
<li><a data-toggle="tab" href="#chronyauthdata">{{ lang._('Auth Data') }}</a></li>
</ul>

<div class="tab-content content-box tab-content">
<div id="general" class="tab-pane fade in active">
<div class="content-box" style="padding-bottom: 1.5em;">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}}
<div class="col-md-12">
<hr />
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_progress"></i></button>
</div>
</div>
</div>
<div id="chronysources" class="tab-pane fade in">
<pre id="listchronysources"></pre>
</div>
<div id="chronysourcestats" class="tab-pane fade in">
<pre id="listchronysourcestats"></pre>
</div>
<div id="chronytracking" class="tab-pane fade in">
<pre id="listchronytracking"></pre>
</div>
<div id="chronyauthdata" class="tab-pane fade in">
<pre id="listchronyauthdata"></pre>
</div>
</div>

<script>

// Put API call into a function, needed for auto-refresh
function update_chronysources() {
ajaxCall(url="/api/chrony/service/chronysources", sendData={}, callback=function(data,status) {
$("#listchronysources").text(data['response']);
});
}

function update_chronysourcestats() {
ajaxCall(url="/api/chrony/service/chronysourcestats", sendData={}, callback=function(data,status) {
$("#listchronysourcestats").text(data['response']);
});
}

// Put API call into a function, needed for auto-refresh
function update_chronytracking() {
ajaxCall(url="/api/chrony/service/chronytracking", sendData={}, callback=function(data,status) {
$("#listchronytracking").text(data['response']);
});
}

function update_chronyauthdata() {
ajaxCall(url="/api/chrony/service/chronyauthdata", sendData={}, callback=function(data,status) {
$("#listchronyauthdata").text(data['response']);
});
}

$(function() {
var data_get_map = {'frm_general_settings':"/api/chrony/general/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});

updateServiceControlUI('chrony');
updateServiceControlUI('chrony');

// Call function update_neighbor with a auto-refresh of 5 seconds
setInterval(update_chronysources, 5000);
setInterval(update_chronysourcestats, 5000);
setInterval(update_chronytracking, 5000);
setInterval(update_chronyauthdata, 5000);

// link save button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/chrony/general/set", formid='frm_general_settings',callback_ok=function(){
Expand Down
24 changes: 24 additions & 0 deletions net/chrony/src/opnsense/service/conf/actions.d/actions_chrony.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,27 @@ command:/usr/local/etc/rc.d/chronyd status;exit 0
parameters:
type:script_output
message:request chrony status

[chronysources]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m unsure we should use chrony prefix here, configctl chrony chronysources looks weird. But not a blocker.

command:/usr/local/bin/chronyc sources
parameters:
type:script_output
message:show chrony sources

[chronysourcestats]
command:/usr/local/bin/chronyc sourcestats
parameters:
type:script_output
message:show chrony sourcestats

[chronytracking]
command:/usr/local/bin/chronyc tracking
parameters:
type:script_output
message:show chrony tracking

[chronyauthdata]
command:/usr/local/bin/chronyc -N authdata
parameters:
type:script_output
message:show chrony authdata