mirror of
https://github.com/unraid/webgui.git
synced 2026-01-20 00:19:59 -06:00
Merge pull request #456 from bergware/master
Added syslog server functionality
This commit is contained in:
@@ -159,7 +159,7 @@ function parityStatus() {
|
||||
if (data) {$.each(data.split(';'),function(k,v) {if ($('#line'+k).length>0) $('#line'+k).html(v);});}
|
||||
timers.parityStatus = setTimeout(parityStatus,3000);
|
||||
if (!data && $('#cancelButton').length>0 && $('#cancelButton').val()=='Cancel') {
|
||||
$('#cancelButton').val('Done').unbind().bind({click:function(){refresh();}});
|
||||
$('#cancelButton').val('Done').prop('onclick',null).off('click').click(function(){refresh();});
|
||||
$('#cancelText').html('');
|
||||
$('#line4').html('completed');
|
||||
}
|
||||
@@ -181,6 +181,16 @@ function stopParity(form,text) {
|
||||
form.submit();
|
||||
<?endif;?>
|
||||
}
|
||||
function pauseParity(form) {
|
||||
$(form).append('<input type="hidden" name="cmdNoCheck" value="Pause">');
|
||||
$('#pauseButton').val('Resume').prop('onclick',null).off('click').click(function(){resumeParity(form);});
|
||||
form.submit();
|
||||
}
|
||||
function resumeParity(form) {
|
||||
$(form).append('<input type="hidden" name="cmdCheck" value="Resume">');
|
||||
$('#pauseButton').val('Pause').prop('onclick',null).off('click').click(function(){pauseParity(form);});
|
||||
form.submit();
|
||||
}
|
||||
function shutdown_now(form,cmd) {
|
||||
$(form).append('<input type="hidden" name="cmd" value="'+cmd+'">');
|
||||
<?if ($confirm['down']):?>
|
||||
@@ -196,7 +206,7 @@ parityStatus();
|
||||
<?if ($tabbed):?>
|
||||
$('.tabs').append(ctrl);
|
||||
if ($.cookie('tab')=='tab0') $('i.toggle').hide();
|
||||
$('#tab'+$('input[name$="tabs"]').length).bind({click:function() {tab0(); $('i.toggle').hide('slow');}});
|
||||
$('#tab'+$('input[name$="tabs"]').length).click(function(){tab0(); $('i.toggle').hide('slow');});
|
||||
<?else:?>
|
||||
$('div[id=title]:not(":last, .disable_diskio")').each(function(){$(this).append(ctrl);});
|
||||
<?endif;?>
|
||||
@@ -230,7 +240,7 @@ $(function(){
|
||||
<input type="hidden" name="startState" value="<?=htmlspecialchars($var['mdState'])?>">
|
||||
<input type="hidden" name="file" value="">
|
||||
<table class="array_status">
|
||||
<?$parity = $var['mdResync']>0 ? '<br><small>Disabled -- Parity operation is running</small>' : '';
|
||||
<?$parity = $var['mdResync'] ? '<br><small>Disabled -- Parity operation is running</small>' : '';
|
||||
$mover = file_exists('/var/run/mover.pid') ? '<br><small>Disabled -- Mover is running</small>' : '';
|
||||
$btrfs = exec('pgrep -cf /sbin/btrfs') ? '<br><small>Disabled -- BTRFS operation is running</small>' : '';
|
||||
switch ($var['fsState']):
|
||||
@@ -248,7 +258,7 @@ $(function(){
|
||||
<small>Yes I want to do this <i class="fa fa-asterisk red-text" ></i></small><span><b>All data is permanently lost !!!<br>This is not used to recover data</b><br><i>Format is never part of a rebuild</i></span></a>
|
||||
</td></tr>
|
||||
<? endif;
|
||||
if (!$parity):
|
||||
if (!$var['mdResyncPos']):
|
||||
if (strstr($var['mdResyncAction'],"recon")):?>
|
||||
<tr><td></td><td><input type="submit" name="cmdCheck" value="Sync"></td><td><strong>Sync</strong> will start <strong>Parity-Sync</strong> and/or <strong>Data-Rebuild</strong>.</td></tr>
|
||||
<? elseif (strstr($var['mdResyncAction'],"clear")):?>
|
||||
@@ -291,17 +301,25 @@ $(function(){
|
||||
endif;
|
||||
else:
|
||||
if ($var['mdResyncAction']=="check"):?>
|
||||
<tr><td>Read-Check in progress.</td><td><input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Read-Check')"></td>
|
||||
<tr><td>Read-Check in progress.</td><td>
|
||||
<input type="button" id="pauseButton"<?if ($var['mdResync']):?> value="Pause" onclick="pauseParity(this.form)"<?else:?> value="Resume" onclick="resumeParity(this.form)"<?endif;?>>
|
||||
<input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Read-Check')"></td>
|
||||
<td id="cancelText"><strong>Cancel</strong> will stop the Read-Check.</td></tr>
|
||||
<? elseif (strstr($var['mdResyncAction'],"check")):?>
|
||||
<tr><td>Parity-Check in progress.</td><td><input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Parity-Check')"></td>
|
||||
<tr><td>Parity-Check in progress.</td><td>
|
||||
<input type="button" id="pauseButton"<?if ($var['mdResync']):?> value="Pause" onclick="pauseParity(this.form)"<?else:?> value="Resume" onclick="resumeParity(this.form)"<?endif;?>>
|
||||
<input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Parity-Check')"></td>
|
||||
<td id="cancelText"><strong>Cancel</strong> will stop the Parity-Check.</td></tr>
|
||||
<? elseif (strstr($var['mdResyncAction'],"recon")):?>
|
||||
<tr><td>Parity-Sync/Data-Rebuild in progress.</td><td><input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Parity-Sync/Data-Rebuild')"></td>
|
||||
<tr><td>Parity-Sync/Data-Rebuild in progress.</td><td>
|
||||
<input type="button" id="pauseButton"<?if ($var['mdResync']):?> value="Pause" onclick="pauseParity(this.form)"<?else:?> value="Resume" onclick="resumeParity(this.form)"<?endif;?>>
|
||||
<input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Parity-Sync/Data-Rebuild')"></td>
|
||||
<td id="cancelText"><strong>Cancel</strong> will stop Parity-Sync/Data-Rebuild.
|
||||
<br>WARNING: canceling may leave the array unprotected!</td></tr>
|
||||
<? elseif (strstr($var['mdResyncAction'],"clear")):?>
|
||||
<tr><td>Clearing in progress.</td><td><input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Clearing')"></td>
|
||||
<tr><td>Clearing in progress.</td><td>
|
||||
<input type="button" id="pauseButton"<?if ($var['mdResync']):?> value="Pause" onclick="pauseParity(this.form)"<?else:?> value="Resume" onclick="resumeParity(this.form)"<?endif;?>>
|
||||
<input type="button" id="cancelButton" value="Cancel" onclick="stopParity(this.form,'Clearing')"></td>
|
||||
<td id="cancelText"><strong>Cancel</strong> will stop Clearing.</td></tr>
|
||||
<? endif;?>
|
||||
<tr><td></td><td><input type="button" value="History" onclick="openBox('/webGui/include/ParityHistory.php','Parity/Read-Check History',600,900,false)"></td><td>Current operation started on <strong><?=my_time($var['sbUpdated'])?></strong></td></tr>
|
||||
|
||||
90
plugins/dynamix/SyslogSettings.page
Normal file
90
plugins/dynamix/SyslogSettings.page
Normal file
@@ -0,0 +1,90 @@
|
||||
Menu="NetworkServices"
|
||||
Title="Syslog Server"
|
||||
Icon="icon-eula"
|
||||
Tag="file-text-o"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2018, Lime Technology
|
||||
* Copyright 2012-2018, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$syslog = @(array)parse_ini_file('/boot/config/rsyslog.cfg');
|
||||
?>
|
||||
<style>
|
||||
select.m130{margin-left:135px}
|
||||
select.m30{margin-left:35px}
|
||||
</style>
|
||||
<script>
|
||||
function localFolder(state) {
|
||||
if (state) $('#local_folder').show(); else $('#local_folder').hide();
|
||||
}
|
||||
$(function(){
|
||||
localFolder(document.syslog.local_server.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
<form markdown="1" name="syslog" method="POST" action="/update.php" target="progressFrame">
|
||||
<input type="hidden" name="#file" value="/boot/config/rsyslog.cfg">
|
||||
<input type="hidden" name="#command" value="/webGui/scripts/rsyslog_config">
|
||||
|
||||
Local syslog server:
|
||||
: <select name="local_server" class="narrow" size="1" onchange="localFolder(this.value)">
|
||||
<?=mk_option($syslog['local_server'], "", "Disabled")?>
|
||||
<?=mk_option($syslog['local_server'], "1", "Enabled")?>
|
||||
</select>
|
||||
<select name="server_protocol" class="narrow m130" size="1">
|
||||
<?=mk_option($syslog['server_protocol'], "udp", "UDP")?>
|
||||
<?=mk_option($syslog['server_protocol'], "tcp", "TCP")?>
|
||||
<?=mk_option($syslog['server_protocol'], "both", "Both")?>
|
||||
</select>
|
||||
<input type="text" name="server_port" class="trim" value="<?=$syslog['server_port']?>" maxlength="4" placeholder="514">
|
||||
|
||||
> Let the server act as a central syslog server and collect syslog messages from other systems.
|
||||
> The server can listen on UDP, TCP or both with a selectable port number.
|
||||
>
|
||||
> Syslog information is stored per IP address. That is every system gets its own syslog file.
|
||||
|
||||
<div markdown="1" id="local_folder" style="display:none">
|
||||
Local syslog folder:
|
||||
: <input type="text" name="server_folder" value="<?=$syslog['server_folder']?>" placeholder="/mnt/user/system">
|
||||
|
||||
> Enter the name of the local folder to store syslog information.
|
||||
> By default this is set to /mnt/user/system
|
||||
>
|
||||
> *Important: make sure the folder EXIST when changing this field*
|
||||
|
||||
</div>
|
||||
|
||||
Remote syslog server:
|
||||
: <input type="text" name="remote_server" class="narrow" value="<?=$syslog['remote_server']?>" maxlength="23" placeholder="name or ip address">
|
||||
<select name="remote_protocol" class="narrow m30" size="1">
|
||||
<?=mk_option($syslog['remote_protocol'], "udp", "UDP")?>
|
||||
<?=mk_option($syslog['remote_protocol'], "tcp", "TCP")?>
|
||||
</select>
|
||||
<input type="text" name="remote_port" class="trim" value="<?=$syslog['remote_port']?>" maxlength="4" placeholder="514">
|
||||
|
||||
> Enter a name or IP address of a remote syslog server.
|
||||
> This will send a copy of the syslog messages to the designated server.
|
||||
|
||||
Mirror syslog to flash:
|
||||
: <select name="syslog_flash" class="narrow" size="1">
|
||||
<?=mk_option($syslog['syslog_flash'], "", "No")?>
|
||||
<?=mk_option($syslog['syslog_flash'], "1", "Yes")?>
|
||||
</select>
|
||||
|
||||
> This setting is OFF by default and must be used with care to avoid unnecessary wear and tear of the USB device.
|
||||
>
|
||||
> Change this setting to YES when troubleshooting is required and it is not possible to get the regular diagnostics information.
|
||||
> A mirror of the syslog file is stored in the **logs** folder of the flash device.
|
||||
|
||||
|
||||
: <input type="submit" value="Apply" disabled><input type="button" value="Done" onclick="done()">
|
||||
</form>
|
||||
6
plugins/dynamix/event/disks_mounted/local_syslog_start
Executable file
6
plugins/dynamix/event/disks_mounted/local_syslog_start
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
ETC=/etc/rsyslog.conf
|
||||
if grep -qP '^#\*\.\* \?remote$' $ETC; then
|
||||
sed -ri 's/^#(\*\.\* \?remote)$/\1/' $ETC
|
||||
/etc/rc.d/rc.rsyslogd restart &> /dev/null
|
||||
fi
|
||||
6
plugins/dynamix/event/unmounting_disks/local_syslog_stop
Executable file
6
plugins/dynamix/event/unmounting_disks/local_syslog_stop
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
ETC=/etc/rsyslog.conf
|
||||
if grep -qP '^\*\.\* \?remote$' $ETC; then
|
||||
sed -ri 's/^(\*\.\* \?remote)$/#\1/' $ETC
|
||||
/etc/rc.d/rc.rsyslogd restart &> /dev/null
|
||||
fi
|
||||
@@ -108,7 +108,7 @@ function device_desc(&$disk) {
|
||||
case 'Cache' : $type = $disk['rotational'] ? ($disk['luksState'] ? 'disk-encrypted' : 'disk') : 'nvme'; break;
|
||||
}
|
||||
$log = $var['fsState']=='Started' ? "<a href=\"#\" title=\"Disk Log Information\" style=\"text-decoration:none\" onclick=\"openBox('/webGui/scripts/disk_log&arg1={$disk['device']}','Disk Log Information',600,900,false);return false\"><i class=\"icon-$type icon\"></i></a>" : "";
|
||||
return $log.my_id($disk['id'])." - $size $unit ({$disk['device']})";
|
||||
return $log."<span style='font-family:bitstream'>".my_id($disk['id'])."</span> - $size $unit ({$disk['device']})";
|
||||
}
|
||||
function assignment(&$disk) {
|
||||
global $var, $devs;
|
||||
@@ -425,12 +425,12 @@ case 'open':
|
||||
break;
|
||||
case 'parity':
|
||||
$data = [];
|
||||
if ($var['mdResync']>0) {
|
||||
$data[] = my_scale($var['mdResync']*1024,$unit,-1)." $unit";
|
||||
$data[] = my_clock(floor((time()-$var['sbUpdated'])/60));
|
||||
$data[] = my_scale($var['mdResyncPos']*1024,$unit)." $unit (".number_format(($var['mdResyncPos']/($var['mdResync']/100+1)),1,$display['number'][0],'')." %)";
|
||||
$data[] = my_scale($var['mdResyncDb']*1024/$var['mdResyncDt'],$unit, 1)." $unit/sec";
|
||||
$data[] = my_clock(round(((($var['mdResyncDt']*(($var['mdResync']-$var['mdResyncPos'])/($var['mdResyncDb']/100+1)))/100)/60),0));
|
||||
if ($var['mdResyncPos']) {
|
||||
$data[] = my_scale($var['mdResyncSize']*1024,$unit,-1)." $unit";
|
||||
$data[] = my_clock(floor((time()-$var['sbUpdated'])/60)).($var['mdResyncDt'] ? '' : ' (paused)');
|
||||
$data[] = my_scale($var['mdResyncPos']*1024,$unit)." $unit (".number_format(($var['mdResyncPos']/($var['mdResyncSize']/100+1)),1,$display['number'][0],'')." %)";
|
||||
$data[] = $var['mdResyncDt'] ? my_scale($var['mdResyncDb']*1024/$var['mdResyncDt'],$unit, 1)." $unit/sec" : '---';
|
||||
$data[] = $var['mdResyncDb'] ? my_clock(round(((($var['mdResyncDt']*(($var['mdResyncSize']-$var['mdResyncPos'])/($var['mdResyncDb']/100+1)))/100)/60),0)) : 'Unknown';
|
||||
$data[] = $var['sbSyncErrs'];
|
||||
echo implode(';',$data);
|
||||
} else {
|
||||
|
||||
@@ -287,7 +287,7 @@ if ($warn>0) {
|
||||
// process parity check, parity sync and data-rebuild notifications
|
||||
$name = 'parity';
|
||||
$last = $saved[$item][$name] ?? '';
|
||||
if ($var['mdResync']>0) {
|
||||
if ($var['mdResyncPos']) {
|
||||
if (!$last) {
|
||||
if (strstr($var['mdResyncAction'],"recon")) {
|
||||
$last = 'Parity sync / Data rebuild';
|
||||
|
||||
67
plugins/dynamix/scripts/rsyslog_config
Executable file
67
plugins/dynamix/scripts/rsyslog_config
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONF=/boot/config/rsyslog.conf
|
||||
ETC=/etc/rsyslog.conf
|
||||
|
||||
# read settings
|
||||
source /boot/config/rsyslog.cfg
|
||||
|
||||
# read $var
|
||||
source /var/local/emhttp/var.ini
|
||||
[[ $fsState == Started ]] || h='#'
|
||||
|
||||
# create local ruleset
|
||||
if ! grep -q '^\$RuleSet local$' $ETC; then
|
||||
sed -ri '/^# limetech - everything goes to syslog.$/a$RuleSet local' $ETC
|
||||
sed -ri '/^#?\*\.\* @@?.*:[0-9]+$/a$DefaultRuleset local' $ETC
|
||||
fi
|
||||
|
||||
# local syslog server
|
||||
if [[ -n $local_server ]]; then
|
||||
if ! grep -q '^\$RuleSet remote$' $ETC; then
|
||||
sed -ri '$a\$RuleSet remote\n*.* ?remote' $ETC
|
||||
fi
|
||||
# enable/disable local logging
|
||||
sed -ri "s/^#?(\*\.\* \?remote)$/$h\1/" $ETC
|
||||
if [[ $server_protocol == tcp || $server_protocol == both ]]; then
|
||||
sed -ri '/^\$InputTCPServerBindRuleset remote$/d;/^\$InputTCPServerRun [0-9]+$/d;s/^#?(\$ModLoad imtcp)/\1/' $ETC
|
||||
sed -ri "\$a\\\$InputTCPServerBindRuleset remote\n\\\$InputTCPServerRun ${server_port:-514}" $ETC
|
||||
[[ $server_protocol == tcp ]] && sed -ri 's/^(\$ModLoad imudp)/#\1/;/^\$InputUDPServerBindRuleset remote$/d;/^\$UDPServerRun [0-9]+$/d' $ETC
|
||||
fi
|
||||
if [[ $server_protocol == udp || $server_protocol == both ]]; then
|
||||
sed -ri '/^\$InputUDPServerBindRuleset remote$/d;/^\$UDPServerRun [0-9]+$/d;s/^#?(\$ModLoad imudp)/\1/' $ETC
|
||||
sed -ri "\$a\\\$InputUDPServerBindRuleset remote\n\\\$UDPServerRun ${server_port:-514}" $ETC
|
||||
[[ $server_protocol == udp ]] && sed -ri 's/^(\$ModLoad imtcp)/#\1/;/^\$InputTCPServerBindRuleset remote$/d;/^\$InputTCPServerRun [0-9]+$/d' $ETC
|
||||
fi
|
||||
sed -ri "/^\\\$template remote,.*$/d;/^#\\\$UDPServerRun [0-9]+.*$/a\\\$template remote,\"${server_folder:-/mnt/user/system}/syslog-%FROMHOST-IP%.log\"" $ETC
|
||||
else
|
||||
sed -ri '/^\$RuleSet remote$/d;/^\*\.\* \?remote$/d;/^\$template remote,".*"$/d;/^\$Input(TCP|UDP)ServerBindRuleset remote$/d;/^\$(InputTCP|UDP)ServerRun [0-9]+$/d;s/^#?\$(ModLoad imtcp|ModLoad imudp)/#\$\1/' $ETC
|
||||
fi
|
||||
|
||||
# remote syslog server
|
||||
if [[ -n $remote_server ]]; then
|
||||
[[ $remote_protocol == udp ]] && com='@' || com='@@'
|
||||
sed -ri "s/^#?(\*\.\*) @@?.*:[0-9]+$/\1 $com$remote_server:${remote_port:-514}/" $ETC
|
||||
else
|
||||
sed -ri 's/^#?(\*\.\* @@?.*:[0-9]+)$/#\1/' $ETC
|
||||
fi
|
||||
|
||||
# mirror syslog to flash
|
||||
if [[ -n $syslog_flash ]]; then
|
||||
if ! grep -q '^\$template flash,' $ETC; then
|
||||
sed -ri '/^#\$UDPServerRun [0-9]+.*$/a$template flash,"/boot/logs/syslog"' $ETC
|
||||
sed -ri '/^\*\.debug .*syslog$/a*.debug ?flash' $ETC
|
||||
fi
|
||||
else
|
||||
sed -ri '/^\$template flash,"\/boot\/logs\/syslog"$/d;/^\*\.debug \?flash/d' $ETC
|
||||
fi
|
||||
|
||||
# copy conf to flash (read settings on reboot)
|
||||
todos <$ETC >$CONF
|
||||
|
||||
# keep local logging disabled at startup
|
||||
# disk mount and disk unmount events are used to start/stop logging
|
||||
sed -ri 's/^(\*\.\* \?remote)/#\1/' $CONF
|
||||
|
||||
# update syslog daemon
|
||||
/etc/rc.d/rc.rsyslogd restart &> /dev/null
|
||||
Reference in New Issue
Block a user