monitoring/SatConfig/cluster/PhysCluster.pm | 2 monitoring/SatConfig/general/NOCpulse-ini | 215 ++++++++++++ monitoring/SatConfig/general/SatConfig-general.spec | 4 monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm | 24 + 4 files changed, 238 insertions(+), 7 deletions(-)
New commits: commit 6e2a26e27f874d4870cc9e9c9d36ea0768b95cff Author: Miroslav Suchý msuchy@redhat.com Date: Thu Jul 23 10:08:38 2009 +0200
457011 - add manpage and documentation
diff --git a/monitoring/SatConfig/general/NOCpulse-ini b/monitoring/SatConfig/general/NOCpulse-ini index 1a08b66..f172631 100644 --- a/monitoring/SatConfig/general/NOCpulse-ini +++ b/monitoring/SatConfig/general/NOCpulse-ini @@ -1,5 +1,20 @@ #!/usr/bin/perl use strict; +# +# Copyright (c) 2009 Red Hat, Inc. +# +# This software is licensed to you under the GNU General Public License, +# version 2 (GPLv2). There is NO WARRANTY for this software, express or +# implied, including the implied warranties of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +# along with this software; if not, see +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +# +# Red Hat trademarks are not licensed under GPLv2. No permission is +# granted to use or replicate Red Hat trademarks that are incorporated +# in this software or its documentation. +# + use lib '/etc/rc.d/np.d'; use NOCpulse::NOCpulseini; use PhysCluster; @@ -14,6 +29,7 @@ my @macros = (); my $set_macro = ''; my $set_param = ''; my $new_value = ''; +my $help = 0; my $save = 0;
GetOptions("all" => $all, @@ -23,8 +39,27 @@ GetOptions("all" => $all, "set-macro:s" => $set_macro, "set-param:s" => $set_param, "new-value:s" => $new_value, + "help" => $help, );
+if ($help) { + print <<HELP; +Usage: + NOCpulse-ini --all + + NOCpulse-ini --group=general --group=mail + + NOCpulse-ini --raw --group mail + + NOCpulse-ini --macro=NPVAR --raw + + NOCpulse-ini --set-macro=SMONURL --new-value='%{XPROTO}://different.url.com' + + NOCpulse-ini --group queues --set-param=polling_interval --new-value=6 +HELP + exit; +} + my $cluster = PhysCluster->newInitialized('/etc/rhn/cluster.ini'); my $localConfig = $cluster->get_LocalConfig; my $ini = NOCpulse::NOCpulseini->new; @@ -102,3 +137,79 @@ if ($save) { $ini->save; }
+ +=pod + +=head1 NAME + +NOCpulse-ini - Show content of monitoring config file NOCpulse.ini and allow you to edit it. + +=head1 SYNOPSIS + +NOCpulse-ini [OPTIONS] + +=head1 DESCRIPTION + +Monitoring main configuration file NOCpulse.ini is human readable, but should not be edited. +This file is deleted and recreated during Monitoring start, therefore all changes in this file +are lost. +Values for this configuration file are stored in database and should be edited with script +NOCpulse-ini. + +WARNING: Changing of values is not recommended, as it can lead to non functional monitoring. + +If you use --set-macro or --set-param, then both database and NOCpulse.ini are updated. + +=head1 OPTIONS + +--all + Dump out full content of NOCpulse.ini as seen by database. + +--group + Dump out content of NOCpulse.ini as seen by database. Dump only part which belongs to this group. + May be specified multiple times. + +--raw + Macros are not expanded. + +--macro + Write value of given macro. + +--set-macro + Change value of this macro. + +--set-param + Change value of parameter. + +--new-value + Set the new value for macro or parameter. + +=head1 EXAMPLES + + NOCpulse-ini --all + + NOCpulse-ini --group=general --group=mail + + NOCpulse-ini --raw --group mail + + NOCpulse-ini --macro=NPVAR --raw + + NOCpulse-ini --set-macro=SMONURL --new-value='%{XPROTO}://different.url.com' + + NOCpulse-ini --group queues --set-param=polling_interval --new-value=6 + +=head1 SEE ALSO + +NOCpulse.ini(8) + +=head1 AUTHOR + +Miroslav Suchý msuchy@redhat.com + +=head1 COPYRIGHT AND LICENSE + +Copyright (c) 2009 Red Hat, Inc. +Released under GNU General Public License, version 2 (GPLv2). + +=cut + diff --git a/monitoring/SatConfig/general/SatConfig-general.spec b/monitoring/SatConfig/general/SatConfig-general.spec index 9f857ca..4f6fdcd 100644 --- a/monitoring/SatConfig/general/SatConfig-general.spec +++ b/monitoring/SatConfig/general/SatConfig-general.spec @@ -22,7 +22,7 @@ to make a monitoring work. %setup -q
%build -#nothing to do here +pod2man --section=8 NOCpulse-ini NOCpulse-ini.8
%install rm -rf $RPM_BUILD_ROOT @@ -40,6 +40,7 @@ install -m 755 validateConfiguration $RPM_BUILD_ROOT%sysv_dir install -m 755 pip $RPM_BUILD_ROOT%sysv_dir install -m 444 SysV.ini $RPM_BUILD_ROOT%sysv_dir ln -s ../../rc.d/np.d/hbResource $RPM_BUILD_ROOT%hb_res_dir/ClusterLeader +install -D -m 644 NOCpulse-ini.8 $RPM_BUILD_ROOT%{_mandir}/man8/NOCpulse-ini.8
%files %defattr(-,root,root,-) @@ -56,6 +57,7 @@ ln -s ../../rc.d/np.d/hbResource $RPM_BUILD_ROOT%hb_res_dir/ClusterLeader %sysv_dir/SysV.ini %hb_res_dir/* %doc 1-STARTUP_SEQUENCE 2-COMMANDS_OVERVIEW 3-CONFIGURATION 4-DEVELOPMENT 5-STEPS_LEGEND +%{_mandir}/man8/NOCpulse-ini.8.*
%clean rm -rf $RPM_BUILD_ROOT
commit 4c8bfa73ccf479355c87141aa6914b2fdb716ffd Author: Miroslav Suchý msuchy@redhat.com Date: Thu Jul 23 09:21:28 2009 +0200
457011 - create NOCpulse-ini - tool to handle NOCpulse.ini
diff --git a/monitoring/SatConfig/general/NOCpulse-ini b/monitoring/SatConfig/general/NOCpulse-ini new file mode 100644 index 0000000..1a08b66 --- /dev/null +++ b/monitoring/SatConfig/general/NOCpulse-ini @@ -0,0 +1,104 @@ +#!/usr/bin/perl +use strict; +use lib '/etc/rc.d/np.d'; +use NOCpulse::NOCpulseini; +use PhysCluster; +use Data::Dumper; +use Getopt::Long; + +#set the defaults +my $all = 0; +my @groups = (); +my $raw = 0; +my @macros = (); +my $set_macro = ''; +my $set_param = ''; +my $new_value = ''; +my $save = 0; + +GetOptions("all" => $all, + "group:s@" => @groups, + "raw" => $raw, + "macro:s@" => @macros, + "set-macro:s" => $set_macro, + "set-param:s" => $set_param, + "new-value:s" => $new_value, + ); + +my $cluster = PhysCluster->newInitialized('/etc/rhn/cluster.ini'); +my $localConfig = $cluster->get_LocalConfig; +my $ini = NOCpulse::NOCpulseini->new; + +if (%$localConfig) { + my $config = (values(%$localConfig))[0]; + my $dbd = $config->get_dbd; + my $dbname = $config->get_dbname; + my $username = $config->get_username; + my $password = $config->get_password; + $ini->connect($dbd, $dbname, $username, $password); + $ini->raw($raw); + $ini->fetch_nocpulseini('INTERNAL'); +} else { + print "Error: This script can be run only on monitoring backend.\n"; + exit 1; +} + +if ($all) { + print $ini->dump; +} elsif (@groups and !$set_param) { + foreach my $group (@groups) { + print $ini->dump_group($group), "\n\n"; + } +} +if (@macros) { + my $list = $ini->fetch_macros; + my %DESCRIPTION; + foreach my $macro (@$list) { + $DESCRIPTION{$macro->{'NAME'}} = $macro->{'DESCRIPTION'}; + } + foreach my $macro (@macros) { + if ($ini->macrodb->{$macro}) { + print "Macro $macro - $DESCRIPTION{$macro}\nexpands to: ", $ini->macrodb->{$macro}, "\n"; + } else { + print "Macro $macro is not defined.\n"; + } + } +} +if ($set_macro) { + my $sql = qq| + UPDATE rhn_config_macro + SET definition=? + WHERE (environment, name) = ( SELECT macro.environment, macro.name + FROM db_environment dbenv, config_macro macro + WHERE UPPER(sys_context('userenv', 'db_name')) = UPPER(dbenv.db_name) + AND DECODE(macro.environment, 'ALL', dbenv.environment, + macro.environment) = dbenv.environment + AND macro.name = ? + ) + |; + my $sth = $ini->dbh->prepare($sql); + $sth->execute($new_value, $set_macro); + print $sth->rows, " record updated.\n"; + $save = 1; +} elsif ($set_param) { + if (!@groups or scalar(@groups) != 1) { + print "Error: You have to specify exactly one group, to which parameter belongs.\n"; + exit 2; + } + my $sql = qq| + UPDATE config_parameter + SET value = ? + WHERE group_name = ? + AND name = ? + |; + my $sth = $ini->dbh->prepare($sql); + $sth->execute($new_value, $groups[0], $set_param); + print $sth->rows, " record updated.\n"; + $save = 1; +} + +if ($save) { + $ini->fetch_nocpulseini('INTERNAL'); + $ini->save; +} + diff --git a/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm b/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm index f7e5f2a..dd47273 100644 --- a/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm +++ b/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm @@ -14,6 +14,7 @@ use Class::MethodMaker filename macrodb paramdb + raw )], new_with_init => 'new', ; @@ -72,17 +73,28 @@ sub save { chmod(0644, $filename) or die "Couldn't chmod $filename: $!"; }
+# return content of NOCpulse.ini (as fetched from db). +# but only for specified group +sub dump_group { + my ($self, $group, $pdb) = @_; + $pdb = $self->paramdb() unless ($pdb); + my $result = "[$group]\n"; + $result .= "# $pdb->{$group}->{'desc'}\n"; + + foreach my $param (sort keys %{$pdb->{$group}->{'params'}}) { + $result .= join('=', $param, $pdb->{$group}->{'params'}->{$param}) . "\n"; + } + return $result; +} + +# return content of NOCpulse.ini (as fetched from db) sub dump { my $self = shift;
my $pdb = $self->paramdb(); my $str; foreach my $grp (sort keys %$pdb) { - $str .= "[$grp]\n"; - $str .= "# $pdb->{$grp}->{'desc'}\n"; - foreach my $param (sort keys %{$pdb->{$grp}->{'params'}}) { - $str .= join('=', $param, $pdb->{$grp}->{'params'}->{$param}) . "\n"; - } + $str .= $self->dump_group($grp, $pdb); $str .= "\n\n"; } return $str; @@ -110,6 +122,7 @@ sub fetch_macros { foreach my $macroname (keys %{$mdb}) { $mdb->{$macroname} = $self->expand($mdb->{$macroname}); } + return $list; }
sub fetch_params { @@ -140,6 +153,7 @@ sub fetch_params { sub expand { my $self = shift; my $value = shift; + return $value if ($self->raw or !$value);
# Store literal percents using OOB data $value =~ s/%%/\0/g;
commit e268316c3d3d0d54645fc5d1b24aa1721dc72ee9 Author: Miroslav Suchý msuchy@redhat.com Date: Wed Jul 22 13:50:37 2009 +0200
remove warning when run as perl -w
diff --git a/monitoring/SatConfig/cluster/PhysCluster.pm b/monitoring/SatConfig/cluster/PhysCluster.pm index feea4e1..3f59404 100644 --- a/monitoring/SatConfig/cluster/PhysCluster.pm +++ b/monitoring/SatConfig/cluster/PhysCluster.pm @@ -246,7 +246,7 @@ sub readFromFile
my $satnumber; my $satNameFile = $self->configValue('satNameFile'); - if (open(FILE,$satNameFile)) { + if ($satNameFile and open(FILE,$satNameFile)) { $satnumber = <FILE>; close(FILE); chomp($satnumber);
spacewalk-commits@lists.fedorahosted.org