add logging to quagga (#206)

* add logging to quagga
* sed -i "s/zebra.log/quagga.log/g" files
* add log viewer
* fix indent; fix typo; upcase first char
This commit is contained in:
Fabian Franz
2017-07-22 18:02:20 +02:00
committed by GitHub
parent b3ac2871e2
commit c460732bbb
14 changed files with 165 additions and 5 deletions
@@ -122,12 +122,16 @@ class DiagnosticsController extends ApiControllerBase
private function get_general_information($name)
{
$backend = new Backend();
return array("response" => json_decode(trim($backend->configdRun("quagga general-$name"))));
return array("response" => json_decode(trim($backend->configdRun("quagga general-$name")), true));
}
public function generalroutesAction()
{
return $this->get_general_information('routes');
}
public function logAction()
{
return $this->get_general_information('log')['response']['general_log'];
}
public function generalroutes6Action()
{
return $this->get_general_information('routes6');
@@ -47,4 +47,9 @@ class DiagnosticsController extends \OPNsense\Base\IndexController
$this->view->title = gettext("Diagnostics: General");
$this->view->pick('OPNsense/Quagga/diagnosticsgeneral');
}
public function logAction()
{
$this->view->title = gettext("Diagnostics: Log");
$this->view->pick('OPNsense/Quagga/log');
}
}
@@ -1,8 +1,32 @@
<form>
<field>
<id>general.enabled</id>
<label>enable</label>
<label>Enable</label>
<type>checkbox</type>
<help>This will activate the routing service.</help>
</field>
<field>
<id>general.enablelogfile</id>
<label>Create a logfile</label>
<type>checkbox</type>
<help>If you check this, a log file will be written to disk.</help>
</field>
<field>
<id>general.logfilelevel</id>
<label>Logfile level</label>
<type>dropdown</type>
<help>This is the detail level of the log. A higher level means more data is logged.</help>
</field>
<field>
<id>general.enablesyslog</id>
<label>Send log messages to syslog</label>
<type>checkbox</type>
<help>Syslog is a service which is made to collect log messages from different software and maybe to a central logging server. Check this box if you have such a setup.</help>
</field>
<field>
<id>general.sysloglevel</id>
<label>Syslog level</label>
<type>dropdown</type>
<help>This is the detail level of the log. A higher level means more data is logged.</help>
</field>
</form>
@@ -6,5 +6,43 @@
<default>0</default>
<Required>Y</Required>
</enabled>
<enablelogfile type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enablelogfile>
<logfilelevel type="OptionField">
<Required>Y</Required>
<multiple>N</multiple>
<default>notifications</default>
<OptionValues>
<critical>Critical</critical>
<emergencies>Emergencies</emergencies>
<errors>Errors</errors>
<alerts>Alerts</alerts>
<warnings>Warnings</warnings>
<notifications>Notifications</notifications>
<informational>Informational</informational>
<debugging>Debugging</debugging>
</OptionValues>
</logfilelevel>
<enablesyslog type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enablesyslog>
<sysloglevel type="OptionField">
<Required>Y</Required>
<multiple>N</multiple>
<default>notifications</default>
<OptionValues>
<critical>Critical</critical>
<emergencies>Emergencies</emergencies>
<errors>Errors</errors>
<alerts>Alerts</alerts>
<warnings>Warnings</warnings>
<notifications>Notifications</notifications>
<informational>Informational</informational>
<debugging>Debugging</debugging>
</OptionValues>
</sysloglevel>
</items>
</model>
@@ -11,6 +11,7 @@
<OSPF VisibleName="OSPF" url="/ui/quagga/diagnostics/ospf" order="20" />
<OSPFv3 VisibleName="OSPFv3" url="/ui/quagga/diagnostics/ospfv3" order="25" />
<BGP VisibleName="BGPv4" url="/ui/quagga/diagnostics/bgp" order="40" />
<LOG VisibleName="Log" url="/ui/quagga/diagnostics/log" order="100" />
</Diagnostics>
</Routing>
</menu>
@@ -0,0 +1,24 @@
<div class="content-box">
<table id="logtable" class="table table-condensed table-hover table-striped" style="table-layout: initial;">
<thead>
<tr>
<th data-column-id="date" data-sortable="false" data-type="string">{{ lang._('Date') }}</th>
<th data-column-id="time" data-sortable="false" data-type="string">{{ lang._('Time') }}</th>
<th data-column-id="service" data-sortable="false" data-type="string">{{ lang._('Service') }}</th>
<th data-column-id="message" data-sortable="false" data-type="string">{{ lang._('Message') }}</th>
</tr>
</thead>
</table>
</div>
<script>
$("#logtable").bootgrid({
ajax: true,
navigation: 0,
url: "/api/quagga/diagnostics/log",
ajaxSettings: { "method": "GET", cache: true },
responseHandler: function(resp) { return {"rows": resp}; },
sortable: false
});
</script>
@@ -119,7 +119,7 @@ class General
if line.length > 10
code, network, ad, metric, via, direct, interface, time = line.scan(entry_regex).first
code = code.split('').map {|c| {short: c, long: meanings[c]}}
entries << {code: code, network: (network || direct), ad: ad, metric: metric, interface: interface, time: time }
entries << {code: code, network: (network || direct), ad: ad, via: via, metric: metric, interface: interface, time: time }
end
end
entries
@@ -128,6 +128,15 @@ class General
def routes6
routes(true)
end
def log
File.read('/var/log/quagga.log').lines.select {|l| l.strip.length > 10}.map do |line|
date, time, service, message = line.split(' ', 4)
date = date.split('/').reverse.join(".") # format dd.mm.yyyy
service = service.split(':').first if service
{date: date, time:time, service: service, message: message }
end
end
end
class OSPF
@@ -433,7 +442,7 @@ class OSPFv3
@vtysh = sh
end
def overview
def overview
lines = @vtysh.execute("show ipv6 ospf6").lines
overview = {}
while line = lines.shift&.strip
@@ -647,7 +656,7 @@ end
require 'optparse'
options = {}
supported_sections = %w{general ospf}
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} -s section [section specific params]"
#### OSPFv2
@@ -689,6 +698,9 @@ OptionParser.new do |opts|
opts.on("-6", "--general-routes6", "Print Routing Table (IPv6)") do |od|
options[:general_routes6] = od
end
opts.on("-l", "--general-log", "Print Logs") do |od|
options[:general_log] = od
end
### BGP
opts.on("-B", "--bgp-overview", "Print an overview of BGP") do |od|
options[:bgp_overview] = od
@@ -14,3 +14,8 @@ chmod 750 /usr/local/etc/quagga
# ensure that quagga can read the configuration files
chown -R $user:$group /usr/local/etc/quagga
chown -R $user:$group /var/run/quagga
# logfile (if used)
touch /var/log/quagga.log
chown $user:$group /var/log/quagga.log
@@ -112,6 +112,13 @@ parameters:
type:script_output
message: Print IPv6 Routing Table
[general-log]
command:/usr/local/opnsense/scripts/quagga/quagga.rb --general-log
parameters:
type:script_output
message: Print IPv6 Routing Table
[general-runningconfig]
command:/usr/local/bin/vtysh -c "show run"
parameters:
@@ -4,6 +4,14 @@
! Zebra configuration saved from vty
! 2017/03/03 20:21:04
!
{% if helpers.exists('OPNsense.quagga.general') %}
{% if helpers.exists('OPNsense.quagga.general.enablelogfile') and OPNsense.quagga.general.enablelogfile == '1' %}
log file /var/log/quagga.log {{ OPNsense.quagga.general.logfilelevel }}
{% endif %}
{% if helpers.exists('OPNsense.quagga.general.enablesyslog') and OPNsense.quagga.general.enablesyslog == '1' %}
log syslog {{ OPNsense.quagga.general.sysloglevel }}
{% endif %}
{% endif %}
!
!
!
@@ -7,6 +7,14 @@
! Zebra configuration saved from vty
! 2017/03/03 20:21:04
!
{% if helpers.exists('OPNsense.quagga.general') %}
{% if helpers.exists('OPNsense.quagga.general.enablelogfile') and OPNsense.quagga.general.enablelogfile == '1' %}
log file /var/log/quagga.log {{ OPNsense.quagga.general.logfilelevel }}
{% endif %}
{% if helpers.exists('OPNsense.quagga.general.enablesyslog') and OPNsense.quagga.general.enablesyslog == '1' %}
log syslog {{ OPNsense.quagga.general.sysloglevel }}
{% endif %}
{% endif %}
!
!
!
@@ -7,6 +7,14 @@
! Zebra configuration saved from vty
! 2017/03/03 20:21:04
!
{% if helpers.exists('OPNsense.quagga.general') %}
{% if helpers.exists('OPNsense.quagga.general.enablelogfile') and OPNsense.quagga.general.enablelogfile == '1' %}
log file /var/log/quagga.log {{ OPNsense.quagga.general.logfilelevel }}
{% endif %}
{% if helpers.exists('OPNsense.quagga.general.enablesyslog') and OPNsense.quagga.general.enablesyslog == '1' %}
log syslog {{ OPNsense.quagga.general.sysloglevel }}
{% endif %}
{% endif %}
!
!
!
@@ -4,6 +4,14 @@
! Zebra configuration saved from vty
! 2017/03/26 22:40:16
!
{% if helpers.exists('OPNsense.quagga.general') %}
{% if helpers.exists('OPNsense.quagga.general.enablelogfile') and OPNsense.quagga.general.enablelogfile == '1' %}
log file /var/log/quagga.log {{ OPNsense.quagga.general.logfilelevel }}
{% endif %}
{% if helpers.exists('OPNsense.quagga.general.enablesyslog') and OPNsense.quagga.general.enablesyslog == '1' %}
log syslog {{ OPNsense.quagga.general.sysloglevel }}
{% endif %}
{% endif %}
!
router zebra
no redistribute rip
@@ -1,7 +1,14 @@
{% if helpers.exists('OPNsense.quagga.general') %}
!
! Zebra configuration saved from vty
! 2017/03/03 20:21:04
!
{% if helpers.exists('OPNsense.quagga.general.enablelogfile') and OPNsense.quagga.general.enablelogfile == '1' %}
log file /var/log/quagga.log {{ OPNsense.quagga.general.logfilelevel }}
{% endif %}
{% if helpers.exists('OPNsense.quagga.general.enablesyslog') and OPNsense.quagga.general.enablesyslog == '1' %}
log syslog {{ OPNsense.quagga.general.sysloglevel }}
{% endif %}
!
!
!
@@ -12,3 +19,4 @@ ipv6 forwarding
!
line vty
!
{% endif %}