1
# Copyright (C) 2008-2012 eBox Technologies S.L.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License, version 2, as
5
# published by the Free Software Foundation.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
# Class: EBox::Events::Model::LogWatcherConfiguration
18
# This class is the model to configurate Log watcher. It has as many
19
# rows as logger exist in eBox
21
# The fields are the following:
23
# - name - the logger name (i18ned)
24
# - filtering - model to configure as many filters as you may need
25
# - enabled - enabled the event notification for that logger
28
package EBox::Events::Model::LogWatcherConfiguration;
32
use base 'EBox::Model::DataTable';
34
use EBox::Exceptions::DataNotFound;
35
use EBox::Events::Model::LogFiltering;
38
use EBox::Model::Manager;
39
use EBox::Types::HasMany;
40
use EBox::Types::Text;
46
use constant FILTERING_MODEL_NAME => 'LogWatcherFiltering';
48
# Group: Public methods
52
# Set in model manager the dynamic models for log watcher
53
# configuration per domain
55
# The result of this method is to include in model manager the
56
# dynamic models (one per log domain)
62
my $manager = EBox::Model::Manager->instance();
64
my $readOnly = $self->parentModule()->isReadOnly();
65
my $logs = EBox::Global->getInstance($readOnly)->modInstance('logs');
66
my $logDomainTables = $logs->getAllTables(1);
67
if (defined ( $logDomainTables)) {
68
while (my ($domain, $tableInfo) = each %{$logDomainTables}) {
69
next if ($domain eq 'events'); # avoid observe recursively itself!
70
$manager->addModel($self->_createFilteringModel($domain, $tableInfo));
79
# <EBox::Model::DataTable::syncRows>
81
# It is overriden because this table is kind of different in
82
# comparation to the normal use of generic data tables.
84
# - The user does not add rows. When we detect the table is
85
# empty we populate the table with the available log domains.
87
# - We check if we have to add/remove one the log domains. That happens
88
# when a new module is installed or an existing one is removed.
92
my ($self, $currentIds) = @_;
94
my $anyChange = undef;
95
my $logs = EBox::Global->modInstance('logs');
97
# Set up every dynamic model
100
# Fetch the current log domains stored in conf
101
my %storedLogDomains;
102
foreach my $id (@{$currentIds}) {
103
my $row = $self->row($id);
104
$storedLogDomains{$row->valueByName('domain')} = 1;
107
# Fetch the current available log domains
108
my %currentLogDomains;
109
my $currentTables = $logs->getAllTables(1);
110
foreach my $table (keys (%{$currentTables})) {
111
next if ($table eq 'events'); # ignore events table
112
$currentLogDomains{$table} = 1;
115
# Add new domains to conf
116
foreach my $domain (keys %currentLogDomains) {
117
next if (exists $storedLogDomains{$domain});
118
$self->addRow('domain' => $domain, 'enabled' => 0);
122
# Remove non-existing domains from conf
123
foreach my $id (@{$currentIds}) {
124
my $row = $self->row($id);
125
my $domain = $row->valueByName('domain');
126
next if (exists $currentLogDomains{$domain});
127
$self->removeRow($id);
128
$self->_removeFilteringModel($domain);
135
# Method: updatedRowNotify
139
# <EBox::Model::DataTable::updatedRowNotify>
143
my ($self, $row, $oldRow, $force) = @_;
145
# Warn if the parent log observer is not enabled
146
if ($row->valueByName('enabled')) {
147
my $eventModel = EBox::Global->modInstance('events')->model('ConfigureWatchers');
148
my $logConfRow = $eventModel->findValue(eventWatcher => 'EBox::Event::Watcher::Log');
149
unless ($logConfRow->valueByName('enabled')) {
150
$self->setMessage(__('Warning! The log watcher is not enabled. '
151
. 'Enable to be notified when logs happen. '
152
. $self->message()));
157
# Method: addedRowNotify
161
# <EBox::Model::DataTable::addedRowNotify>
165
my ($self, $row, $force) = @_;
167
# Warn if the parent log observer is not enabled
168
if ( $row->valueByName('enabled') ) {
169
my $eventModel = EBox::Global->modInstance('events')->model('ConfigureWatchers');
170
my $logConfRow = $eventModel->findValue( eventWatcher => 'EBox::Event::Watcher::Log' );
171
unless ( $logConfRow->valueByName('enabled') ) {
172
$self->setMessage(__('Warning! The log watcher is not enabled. '
173
. 'Enable to be notified when logs happen. '
174
. $self->message()));
180
# Group: Protected methods
186
# <EBox::Model::DataTable::_table>
192
new EBox::Types::Text(
193
fieldName => 'domain',
194
printableName => __('Domain'),
197
new EBox::Types::HasMany(
198
fieldName => 'filters',
199
printableName => __('Filtering'),
200
foreignModelAcquirer => \&acquireFilteringModel,
201
backView => '/Events/View/LogWatcherConfiguration?directory=Log',
206
tableName => 'LogWatcherConfiguration',
207
printableTableName => __('Configure log watchers'),
208
modelDomain => 'Events',
209
printableRowName => __('Log watcher'),
210
defaultActions => [ 'editField', 'changeView' ],
211
tableDescription => \@tableDesc,
212
class => 'dataTable',
215
defaultEnabledValue => 0,
221
# Group: Callback functions
223
# Function: acquireFilteringModel
225
# Callback function used to gather the foreignModel and its view
226
# in order to configure the log event watcher filters
230
# row - hash ref with the content what is stored in GConf
231
# regarding to this row.
235
# String - the foreign model to configurate the filters
236
# associated to the log event watcher
238
sub acquireFilteringModel
242
my $logDomain = $row->valueByName('domain');
244
return 'events/' . FILTERING_MODEL_NAME . "_$logDomain";
247
# Group: Private methods
249
# Create a new filtering model given a
250
# log domain and notify this new model to model manager
251
sub _createFilteringModel
253
my ($self, $domain, $domainTableInfo) = @_;
255
if (not defined $domainTableInfo) {
256
my $logs = EBox::Global->modInstance('logs');
257
$domainTableInfo = $logs->getTableInfo($domain);
260
my $filteringModel = new EBox::Events::Model::LogFiltering(confmodule => $self->{confmodule},
261
directory => $self->{confdir},
262
tableInfo => $domainTableInfo);
263
return $filteringModel;
266
# Remove an existing filtering model given a
267
# log domain and notify this removal to model manager
268
sub _removeFilteringModel
270
my ($self, $domain) = @_;
272
my $modelManager = EBox::Model::Manager->instance();
273
$modelManager->removeModel('events/' . FILTERING_MODEL_NAME . "_$domain");
276
# Method: viewCustomizer
278
# Overrides <EBox::Model::DataTable::viewCustomizer> to
279
# provide a custom HTML title with breadcrumbs
285
my $custom = $self->SUPER::viewCustomizer();
286
$custom->setHTMLTitle([
288
title => __('Events'),
289
link => '/Events/Composite/General',
292
title => __('Log Observer Watcher'),