monitoring/PerlModules/NP/Probe/monitoring-data-cleanup | 161 +++++++++++++++
monitoring/PerlModules/NP/Probe/perl-NOCpulse-Probe.spec | 5
2 files changed, 165 insertions(+), 1 deletion(-)
New commits:
commit 669c2b6fc07eb452f5cd26506d711993bf51dbf4
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 14:12:09 2009 +0200
520101 - add description section to man page
diff --git a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
index 28b40f7..41a72b6 100755
--- a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
+++ b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
@@ -116,6 +116,13 @@ monitoring-data-cleanup [OPTIONS]
=head1 DESCRIPTION
+This script delete data from monitoring probes older than given time frame.
+It can be useful to run from cron to periodicaly delete data which is not
+interested for you.
+
+Additionaly - in Spacewalk 0.5 and older we did not deletes data when probe
+has been deleted. And if you did not push scout configs you will be getting
+data for deleted probes too. This script will delete them too.
=head1 OPTIONS
commit 98230aa9238bb3c40633d69a022735604f4675d9
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 14:00:06 2009 +0200
520101 - rename --delete-before to --keep-monitoring-data
diff --git a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
index a924ca7..28b40f7 100755
--- a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
+++ b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
@@ -33,7 +33,7 @@ my ($sql, $err, $sth);
GetOptions(
"delete-unmatched!" => \$delete_unmatched,
"dry-run" => \$dry_run,
- "delete-before:s" => \$delta,
+ "keep-monitoring-data:s" => \$delta,
"help" => \$help,
);
@@ -42,6 +42,7 @@ if ($help) {
Usage:
monitoring-data-cleanup --no-delete-unmatched
+ monitoring-data-cleanup --keep-monitoring-data "1Y 6M"
HELP
exit;
}
@@ -125,7 +126,7 @@ monitoring-data-cleanup [OPTIONS]
--no-delete-unmatched
Delete data from probes, which have been already deleted. Default is to delete
them.
---delete-before DELTA
+--keep-monitoring-data DELTA
Delete data older than DELTA. Recognized deltas are of the form:
+Yy +Mm +Ww +Dd +Hh +MNmn +Ss
Examples:
commit d7c805b064562fbf376880d43c08668b0a3aaee3
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 13:53:41 2009 +0200
520101 - add monitoring-data-cleanup to package perl-NOCpulse-Probe
diff --git a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
old mode 100644
new mode 100755
diff --git a/monitoring/PerlModules/NP/Probe/perl-NOCpulse-Probe.spec
b/monitoring/PerlModules/NP/Probe/perl-NOCpulse-Probe.spec
index e3aff97..784a8d8 100644
--- a/monitoring/PerlModules/NP/Probe/perl-NOCpulse-Probe.spec
+++ b/monitoring/PerlModules/NP/Probe/perl-NOCpulse-Probe.spec
@@ -33,7 +33,8 @@ mkdir -p $RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/Utils/test
mkdir -p $RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/SNMP/test
mkdir -p $RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/test
-install -m 755 -D rhn-runprobe $RPM_BUILD_ROOT/%{_bindir}/rhn-runprobe
+install -m 755 -D rhn-runprobe $RPM_BUILD_ROOT%{_bindir}/rhn-runprobe
+install -m 755 monitoring-data-cleanup $RPM_BUILD_ROOT%{_bindir}/monitoring-data-cleanup
install -m 644 Config/*.pm $RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/Config/
install -m 644 Config/test/*.pm
$RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/Config/test/
install -m 644 DataSource/*.pm
$RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/DataSource/
@@ -57,6 +58,7 @@ mkdir -p $RPM_BUILD_ROOT%{_mandir}/man3
/usr/bin/pod2man $RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/Shell/SQLPlus.pm |gzip
> $RPM_BUILD_ROOT%{_mandir}/man3/NOCpulse::Probe::Shell::SQLPlus.3pm.gz
/usr/bin/pod2man $RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/Shell/Local.pm |gzip
> $RPM_BUILD_ROOT%{_mandir}/man3/NOCpulse::Probe::Shell::Local.3pm.gz
/usr/bin/pod2man $RPM_BUILD_ROOT%{perl_vendorlib}/NOCpulse/Probe/Shell/Unix.pm |gzip >
$RPM_BUILD_ROOT%{_mandir}/man3/NOCpulse::Probe::Shell::Unix.3pm.gz
+/usr/bin/pod2man $RPM_BUILD_ROOT/%{_bindir}/monitoring-data-cleanup | gzip >
$RPM_BUILD_ROOT%{_mandir}/man3/monitoring-data-cleanup.3pm.gz
%clean
rm -rf $RPM_BUILD_ROOT
@@ -64,6 +66,7 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%{_bindir}/rhn-runprobe
+%{_bindir}/monitoring-data-cleanup
%dir %{perl_vendorlib}/NOCpulse
%{perl_vendorlib}/NOCpulse/*
%{_mandir}/man3/*
commit aa0065d9e98653c8abb36c1c2598251517b991b0
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 13:01:49 2009 +0200
520101 - optimize sql query per mmraka recommendation
diff --git a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
index 95dc243..a924ca7 100644
--- a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
+++ b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
@@ -70,12 +70,13 @@ if ($delete_unmatched) {
$ini->dbh->begin_work;
print "Deleting data from already deleted probes...\n";
$sql = qq|
- delete from time_series
- where time_series.rowid in (
- select time_series.rowid from time_series
- left join rhn_probe
- on
SUBSTR(O_ID,INSTR(O_ID,'-')+1,(INSTR(O_ID,'-',INSTR(O_ID,'-')+1)-INSTR(O_ID,'-'))-1)
= rhn_probe.recid
- where rhn_probe.recid is null
+ delete from time_series
+ where not exists (
+ select 1 from rhn_probe
+ where substr(time_series.o_id,
+ instr(time_series.o_id,'-')+1,
+
(instr(time_series.o_id,'-',instr(time_series.o_id,'-')+1)-instr(time_series.o_id,'-'))-1
+ ) = rhn_probe.recid
)
|;
$sth = $ini->dbh->prepare($sql);
commit 0c36040ecaeab46753602c3cafe367d35b8aef59
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 12:07:27 2009 +0200
520101 - fill in documention for --dry-run and --delete-before DELTA
diff --git a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
index 02c11b2..95dc243 100644
--- a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
+++ b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
@@ -117,14 +117,27 @@ monitoring-data-cleanup [OPTIONS]
=head1 OPTIONS
+--dry-run
+ No changes will be commited. All data will remain intact.
+
--delete-unmatched
--no-delete-unmatched
Delete data from probes, which have been already deleted. Default is to delete
them.
+--delete-before DELTA
+ Delete data older than DELTA. Recognized deltas are of the form:
+ +Yy +Mm +Ww +Dd +Hh +MNmn +Ss
+ Examples:
+ "1year 2 months 3hours"
+ "2 business days"
+ For more information about format see ParseDateDelta section of Date::Manip(3)
+
--help
Display this help.
-=head1 EXAMPLES
+=head1 SEE ALSO
+
+Date::Manip(3)
=head1 AUTHOR
commit 19436226f323337e6e6a31a814101184b763105a
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 11:55:15 2009 +0200
520101 - rename delete-old-probes to monitoring-data-cleanup
diff --git a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
index cac88f6..02c11b2 100644
--- a/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
+++ b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
@@ -40,7 +40,7 @@ GetOptions(
if ($help) {
print <<HELP;
Usage:
- delete-old-probes --no-delete-unmatched
+ monitoring-data-cleanup --no-delete-unmatched
HELP
exit;
@@ -106,11 +106,11 @@ if ($delta) {
=head1 NAME
-delete-old-probes - Delete unused and old data from monitoring probes.
+monitoring-data-cleanup - Delete unused and old data from monitoring probes.
=head1 SYNOPSIS
-delete-old-probes [OPTIONS]
+monitoring-data-cleanup [OPTIONS]
=head1 DESCRIPTION
commit fbf34a16223f614a3d0b8ba1b250b8ffffa37772
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 11:53:43 2009 +0200
520101 - rename delete-old-probes to monitoring-data-cleanup
diff --git a/monitoring/PerlModules/NP/Probe/delete-old-probes
b/monitoring/PerlModules/NP/Probe/delete-old-probes
deleted file mode 100644
index cac88f6..0000000
--- a/monitoring/PerlModules/NP/Probe/delete-old-probes
+++ /dev/null
@@ -1,139 +0,0 @@
-#!/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;
-
-use Date::Manip;
-use Getopt::Long;
-
-#set the defaults
-my $delete_unmatched = 1;
-my $delta = "";
-my $dry_run = 0;
-my $help = 0;
-
-my ($sql, $err, $sth);
-
-GetOptions(
- "delete-unmatched!" => \$delete_unmatched,
- "dry-run" => \$dry_run,
- "delete-before:s" => \$delta,
- "help" => \$help,
- );
-
-if ($help) {
- print <<HELP;
-Usage:
- delete-old-probes --no-delete-unmatched
-
-HELP
- exit;
-}
-if ($dry_run) {
- print "Warning: Dry run active - no changes will be made.\n";
-}
-
-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->fetch_nocpulseini('INTERNAL');
-} else {
- print "Error: This script can be run only on monitoring backend.\n";
- exit 1;
-}
-
-if ($delete_unmatched) {
- $ini->dbh->begin_work;
- print "Deleting data from already deleted probes...\n";
- $sql = qq|
- delete from time_series
- where time_series.rowid in (
- select time_series.rowid from time_series
- left join rhn_probe
- on
SUBSTR(O_ID,INSTR(O_ID,'-')+1,(INSTR(O_ID,'-',INSTR(O_ID,'-')+1)-INSTR(O_ID,'-'))-1)
= rhn_probe.recid
- where rhn_probe.recid is null
- )
- |;
- $sth = $ini->dbh->prepare($sql);
- $sth->execute();
- print "\t", $sth->rows, " record deleted.\n";
- $dry_run ? $ini->dbh->rollback : $ini->dbh->commit;
-}
-
-if ($delta) {
- # delete probes older then $delta
- my $date=DateCalc("today", "- $delta", \$err);
- if ($err > 0) {
- print STDERR "Error: $delta is not valid delta of date.\n";
- exit 1;
- }
- print UnixDate($date,"Deleting probes data older than %T %b %e,
%Y...\n");
- $sql = qq|delete from time_series where entry_time < ?|;
- $ini->dbh->begin_work;
- $sth = $ini->dbh->prepare($sql);
- $sth->execute(UnixDate($date,"%s"));
- print "\t", $sth->rows, " record deleted.\n";
- $dry_run ? $ini->dbh->rollback : $ini->dbh->commit;
-} else {
- print "No date delta specified. I do not know what to delete.\n";
-}
-
-=pod
-
-=head1 NAME
-
-delete-old-probes - Delete unused and old data from monitoring probes.
-
-=head1 SYNOPSIS
-
-delete-old-probes [OPTIONS]
-
-=head1 DESCRIPTION
-
-
-=head1 OPTIONS
-
---delete-unmatched
---no-delete-unmatched
- Delete data from probes, which have been already deleted. Default is to delete
them.
-
---help
- Display this help.
-
-=head1 EXAMPLES
-
-=head1 AUTHOR
-
-Miroslav Suchý <msuchy(a)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/PerlModules/NP/Probe/monitoring-data-cleanup
b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
new file mode 100644
index 0000000..cac88f6
--- /dev/null
+++ b/monitoring/PerlModules/NP/Probe/monitoring-data-cleanup
@@ -0,0 +1,139 @@
+#!/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;
+
+use Date::Manip;
+use Getopt::Long;
+
+#set the defaults
+my $delete_unmatched = 1;
+my $delta = "";
+my $dry_run = 0;
+my $help = 0;
+
+my ($sql, $err, $sth);
+
+GetOptions(
+ "delete-unmatched!" => \$delete_unmatched,
+ "dry-run" => \$dry_run,
+ "delete-before:s" => \$delta,
+ "help" => \$help,
+ );
+
+if ($help) {
+ print <<HELP;
+Usage:
+ delete-old-probes --no-delete-unmatched
+
+HELP
+ exit;
+}
+if ($dry_run) {
+ print "Warning: Dry run active - no changes will be made.\n";
+}
+
+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->fetch_nocpulseini('INTERNAL');
+} else {
+ print "Error: This script can be run only on monitoring backend.\n";
+ exit 1;
+}
+
+if ($delete_unmatched) {
+ $ini->dbh->begin_work;
+ print "Deleting data from already deleted probes...\n";
+ $sql = qq|
+ delete from time_series
+ where time_series.rowid in (
+ select time_series.rowid from time_series
+ left join rhn_probe
+ on
SUBSTR(O_ID,INSTR(O_ID,'-')+1,(INSTR(O_ID,'-',INSTR(O_ID,'-')+1)-INSTR(O_ID,'-'))-1)
= rhn_probe.recid
+ where rhn_probe.recid is null
+ )
+ |;
+ $sth = $ini->dbh->prepare($sql);
+ $sth->execute();
+ print "\t", $sth->rows, " record deleted.\n";
+ $dry_run ? $ini->dbh->rollback : $ini->dbh->commit;
+}
+
+if ($delta) {
+ # delete probes older then $delta
+ my $date=DateCalc("today", "- $delta", \$err);
+ if ($err > 0) {
+ print STDERR "Error: $delta is not valid delta of date.\n";
+ exit 1;
+ }
+ print UnixDate($date,"Deleting probes data older than %T %b %e,
%Y...\n");
+ $sql = qq|delete from time_series where entry_time < ?|;
+ $ini->dbh->begin_work;
+ $sth = $ini->dbh->prepare($sql);
+ $sth->execute(UnixDate($date,"%s"));
+ print "\t", $sth->rows, " record deleted.\n";
+ $dry_run ? $ini->dbh->rollback : $ini->dbh->commit;
+} else {
+ print "No date delta specified. I do not know what to delete.\n";
+}
+
+=pod
+
+=head1 NAME
+
+delete-old-probes - Delete unused and old data from monitoring probes.
+
+=head1 SYNOPSIS
+
+delete-old-probes [OPTIONS]
+
+=head1 DESCRIPTION
+
+
+=head1 OPTIONS
+
+--delete-unmatched
+--no-delete-unmatched
+ Delete data from probes, which have been already deleted. Default is to delete
them.
+
+--help
+ Display this help.
+
+=head1 EXAMPLES
+
+=head1 AUTHOR
+
+Miroslav Suchý <msuchy(a)redhat.com>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2009 Red Hat, Inc.
+Released under GNU General Public License, version 2 (GPLv2).
+
+=cut
+
commit 62c95b0226b50491d52663a3e38b12e40432368f
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 11:53:02 2009 +0200
520101 - implement --delete-before and --dry-run
diff --git a/monitoring/PerlModules/NP/Probe/delete-old-probes
b/monitoring/PerlModules/NP/Probe/delete-old-probes
index d2a715a..cac88f6 100644
--- a/monitoring/PerlModules/NP/Probe/delete-old-probes
+++ b/monitoring/PerlModules/NP/Probe/delete-old-probes
@@ -18,14 +18,22 @@ use strict;
use lib '/etc/rc.d/np.d';
use NOCpulse::NOCpulseini;
use PhysCluster;
+
+use Date::Manip;
use Getopt::Long;
#set the defaults
my $delete_unmatched = 1;
+my $delta = "";
+my $dry_run = 0;
my $help = 0;
+my ($sql, $err, $sth);
+
GetOptions(
"delete-unmatched!" => \$delete_unmatched,
+ "dry-run" => \$dry_run,
+ "delete-before:s" => \$delta,
"help" => \$help,
);
@@ -37,6 +45,9 @@ Usage:
HELP
exit;
}
+if ($dry_run) {
+ print "Warning: Dry run active - no changes will be made.\n";
+}
my $cluster = PhysCluster->newInitialized('/etc/rhn/cluster.ini');
my $localConfig = $cluster->get_LocalConfig;
@@ -56,9 +67,9 @@ if (%$localConfig) {
}
if ($delete_unmatched) {
+ $ini->dbh->begin_work;
print "Deleting data from already deleted probes...\n";
-$ini->dbh->begin_work;
- my $sql = qq|
+ $sql = qq|
delete from time_series
where time_series.rowid in (
select time_series.rowid from time_series
@@ -67,10 +78,28 @@ $ini->dbh->begin_work;
where rhn_probe.recid is null
)
|;
- my $sth = $ini->dbh->prepare($sql);
+ $sth = $ini->dbh->prepare($sql);
$sth->execute();
- print $sth->rows, " record deleted. and rollbacked\n";
- $ini->dbh->rollback;
+ print "\t", $sth->rows, " record deleted.\n";
+ $dry_run ? $ini->dbh->rollback : $ini->dbh->commit;
+}
+
+if ($delta) {
+ # delete probes older then $delta
+ my $date=DateCalc("today", "- $delta", \$err);
+ if ($err > 0) {
+ print STDERR "Error: $delta is not valid delta of date.\n";
+ exit 1;
+ }
+ print UnixDate($date,"Deleting probes data older than %T %b %e,
%Y...\n");
+ $sql = qq|delete from time_series where entry_time < ?|;
+ $ini->dbh->begin_work;
+ $sth = $ini->dbh->prepare($sql);
+ $sth->execute(UnixDate($date,"%s"));
+ print "\t", $sth->rows, " record deleted.\n";
+ $dry_run ? $ini->dbh->rollback : $ini->dbh->commit;
+} else {
+ print "No date delta specified. I do not know what to delete.\n";
}
=pod
commit 57158883d972af8e5a1cf112f89316798564bad7
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Aug 28 10:46:21 2009 +0200
520101 - first version of delete-old-probes
This one only delete data from already deleted probes.
diff --git a/monitoring/PerlModules/NP/Probe/delete-old-probes
b/monitoring/PerlModules/NP/Probe/delete-old-probes
new file mode 100644
index 0000000..d2a715a
--- /dev/null
+++ b/monitoring/PerlModules/NP/Probe/delete-old-probes
@@ -0,0 +1,110 @@
+#!/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;
+use Getopt::Long;
+
+#set the defaults
+my $delete_unmatched = 1;
+my $help = 0;
+
+GetOptions(
+ "delete-unmatched!" => \$delete_unmatched,
+ "help" => \$help,
+ );
+
+if ($help) {
+ print <<HELP;
+Usage:
+ delete-old-probes --no-delete-unmatched
+
+HELP
+ exit;
+}
+
+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->fetch_nocpulseini('INTERNAL');
+} else {
+ print "Error: This script can be run only on monitoring backend.\n";
+ exit 1;
+}
+
+if ($delete_unmatched) {
+ print "Deleting data from already deleted probes...\n";
+$ini->dbh->begin_work;
+ my $sql = qq|
+ delete from time_series
+ where time_series.rowid in (
+ select time_series.rowid from time_series
+ left join rhn_probe
+ on
SUBSTR(O_ID,INSTR(O_ID,'-')+1,(INSTR(O_ID,'-',INSTR(O_ID,'-')+1)-INSTR(O_ID,'-'))-1)
= rhn_probe.recid
+ where rhn_probe.recid is null
+ )
+ |;
+ my $sth = $ini->dbh->prepare($sql);
+ $sth->execute();
+ print $sth->rows, " record deleted. and rollbacked\n";
+ $ini->dbh->rollback;
+}
+
+=pod
+
+=head1 NAME
+
+delete-old-probes - Delete unused and old data from monitoring probes.
+
+=head1 SYNOPSIS
+
+delete-old-probes [OPTIONS]
+
+=head1 DESCRIPTION
+
+
+=head1 OPTIONS
+
+--delete-unmatched
+--no-delete-unmatched
+ Delete data from probes, which have been already deleted. Default is to delete
them.
+
+--help
+ Display this help.
+
+=head1 EXAMPLES
+
+=head1 AUTHOR
+
+Miroslav Suchý <msuchy(a)redhat.com>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2009 Red Hat, Inc.
+Released under GNU General Public License, version 2 (GPLv2).
+
+=cut
+