2 # Copyright (C) 2010 Stanislav Sinyagin
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 # $Id: flushmonitors.in,v 1.1 2010-12-27 00:04:01 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 BEGIN { require '@torrus_config_pl@'; }
26 use Torrus::SiteConfig;
27 use Torrus::ConfigTree;
30 exit(1) if not Torrus::SiteConfig::verify();
39 my $ok = GetOptions ('tree=s' => \@trees,
42 'verbose' => \$verbose,
43 'help' => \$help_needed);
45 if( not $ok or not (scalar(@trees) or $all_trees) or
46 $help_needed or scalar(@ARGV) > 0 )
48 print STDERR "Usage: $0 --tree=NAME [options...]\n",
49 "The utility flushes all monitor alarms and dynamic tokenset members\n",
51 " --tree=NAME tree name(s) to flush\n",
52 " --all flush all trees\n",
53 " --debug set the log level to debug\n",
54 " --verbose set the log level to info\n",
55 " --help this help message\n";
61 @trees = Torrus::SiteConfig::listTreeNames();
66 Torrus::Log::setLevel('debug');
70 Torrus::Log::setLevel('verbose');
74 &Torrus::DB::setSafeSignalHandlers();
76 Verbose(sprintf('Torrus version %s', '@VERSION@'));
78 foreach my $tree ( @trees )
80 if( not Torrus::SiteConfig::treeExists( $tree ) )
82 Error("Tree named \"" . $tree . "\" does not exist");
86 &Torrus::DB::checkInterrupted();
88 Verbose("Flushing alarms and tokensets for the tree: $tree");
90 my $config_tree = new Torrus::ConfigTree( -TreeName => $tree,
92 if( not defined( $config_tree ) )
97 my $db = new Torrus::DB('monitor_alarms',
102 my $cursor = $db->cursor(-Write => 1);
103 while( my ($key, $timers) = $db->next($cursor) )
105 Debug('Deleting alarm: ' . $key);
106 $db->c_del( $cursor );
112 &Torrus::DB::checkInterrupted();
115 foreach my $ts ( $config_tree->getTsets() )
117 Debug('Processing tokenset: ' . $ts);
119 foreach my $member ( $config_tree->tsetMembers( $ts ) )
121 my $origin = $config_tree->tsetMembers( $ts, $member );
123 if( not defined( $origin ) or $origin ne 'static' )
125 my $path = $config_tree->path($member);
126 $config_tree->tsetDelMember($ts, $member);
127 Verbose('deleted ' . $path . ' from tokenset: ' . $ts);
133 &Torrus::DB::cleanupEnvironment();
141 # indent-tabs-mode: nil
142 # perl-indent-level: 4