/usr/share/perl5/Octopussy/Loglevel.pm is in octopussy 1.0.6-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | # $HeadURL$
# $Revision: 586 $
# $Date: 2012-07-04 00:17:56 +0100 (Wed, 04 Jul 2012) $
# $Author: sebthebert $
=head1 NAME
Octopussy::Loglevel - Octopussy Loglevel module
=cut
package Octopussy::Loglevel;
use strict;
use warnings;
use Readonly;
use List::MoreUtils qw(uniq);
use AAT::Utils qw( ARRAY NOT_NULL );
use AAT::XML;
use Octopussy::Device;
use Octopussy::FS;
use Octopussy::Loglevel;
use Octopussy::Service;
Readonly my $FILE_LOGLEVEL => 'loglevel';
=head1 FUNCTIONS
=head2 List(\@dev_list, \@serv_list)
Get list of loglevel entries
=cut
sub List
{
my ($dev_list, $serv_list) = @_;
my @list = ();
if ((NOT_NULL($dev_list)) || (NOT_NULL($serv_list)))
{
my %level = ();
my %color = Colors();
my %levels = Levels();
my @services = (
(NOT_NULL($serv_list))
? ARRAY($serv_list)
: Octopussy::Device::Services(ARRAY($dev_list))
);
@services = sort(uniq(@services));
foreach my $s (@services)
{
@services = Octopussy::Device::Services(ARRAY($dev_list))
if ($s eq '-ANY-');
}
@services = sort(uniq(@services));
foreach my $m (Octopussy::Service::Messages(@services))
{
$level{$m->{loglevel}} = 1;
}
foreach my $k (keys %level)
{
push @list,
{
value => $k,
label => $k,
color => $color{$k},
level => $levels{$k}
};
}
}
else
{
my %field;
my $conf = AAT::XML::Read(Octopussy::FS::File($FILE_LOGLEVEL));
foreach my $l (ARRAY($conf->{loglevel}))
{
$field{$l->{level}} = 1;
}
foreach my $f (reverse sort keys %field)
{
foreach my $l (ARRAY($conf->{loglevel}))
{
$l->{label} = $l->{value};
push @list, $l if ($l->{level} eq $f);
}
}
}
return (undef) if (scalar(@list) == 0);
return (@list);
}
=head2 List_And_Any(\@dev_list, \@serv_list)
Get list of loglevel entries and '-ANY-'
=cut
sub List_And_Any
{
my ($dev_list, $serv_list) = @_;
my @list = ('-ANY-');
push @list, List($dev_list, $serv_list);
return (undef) if (scalar(@list) == 0);
return (@list);
}
=head2 String_List($devices, $services)
Returns Loglevel List as a string like 'Loglevel list: <loglevel_list>'
=cut
sub String_List
{
my ($devices, $services) = @_;
my @d_unknowns = Octopussy::Device::Unknowns(@{$devices});
my @s_unknowns = Octopussy::Service::Unknowns(@{$services});
if (scalar @d_unknowns)
{
return (sprintf '[ERROR] Unknown Device(s): %s', join ', ', @d_unknowns);
}
elsif (scalar @s_unknowns)
{
return (sprintf '[ERROR] Unknown Service(s): %s', join ', ', @s_unknowns);
}
else
{
my @data = Octopussy::Loglevel::List($devices, $services);
my @list = ('-ANY-');
foreach my $d (@data) { push @list, $d->{value}; }
return ('Loglevel list: ' . join ', ', sort @list);
}
}
=head2 Unknowns(@loglevels)
Returns list of Unknown Loglevels in @loglevels list
=cut
sub Unknowns
{
my @loglevels = @_;
my @unknowns = ();
my %exist = map { $_->{label} => 1 } List();
foreach my $l (@loglevels)
{
push @unknowns, $l
if (NOT_NULL($l) && (!defined $exist{$l}) && ($l =~ /^-ANY-$/i));
}
return (@unknowns);
}
=head2 Colors()
=cut
sub Colors
{
my %color = ();
my $conf = AAT::XML::Read(Octopussy::FS::File($FILE_LOGLEVEL));
foreach my $l (ARRAY($conf->{loglevel}))
{
$color{$l->{value}} = $l->{color};
}
return (%color);
}
=head2 Levels()
=cut
sub Levels
{
my %level = ();
my $conf = AAT::XML::Read(Octopussy::FS::File($FILE_LOGLEVEL));
foreach my $l (ARRAY($conf->{loglevel}))
{
$level{$l->{value}} = $l->{level};
}
return (%level);
}
=head2 Valid_Name($name)
Checks that '$name' is valid for an Alert name
=cut
sub Valid_Name
{
my $name = shift;
my $conf = AAT::XML::Read(Octopussy::FS::File($FILE_LOGLEVEL));
my $re_loglevel = join '|', map{ $_->{value} } ARRAY($conf->{loglevel});
return (1) if ((NOT_NULL($name)) && ($name =~ /^$re_loglevel$/i));
return (0);
}
1;
=head1 AUTHOR
Sebastien Thebert <octo.devel@gmail.com>
=cut
|