2 # Copyright (C) 2002 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: genlist.in,v 1.1 2010-12-27 00:04:01 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 BEGIN { require '@torrus_config_pl@'; }
27 use Torrus::ConfigTree;
28 use Torrus::SiteConfig;
30 exit(1) if not Torrus::SiteConfig::verify();
34 my $listWhat = 'rrdfiles';
35 my $selectType = 'all';
39 my %listingsSupported =
52 my $ok = GetOptions ('tree=s' => \$tree,
53 'path=s' => \$initPath,
54 'what=s' => \$listWhat,
55 'type=s' => \$selectType,
56 'help' => \$help_needed);
58 if( not $ok or not $tree or $help_needed or
59 not $listingsSupported{$listWhat}{$selectType} or scalar(@ARGV) > 0 )
61 print STDERR "Usage: $0 --tree=NAME [options...]\n",
63 " --tree=NAME tree name\n",
64 " --path=/PATH [".$initPath."] subtree name\n",
65 " --what=WHAT [".$listWhat."] what to list\n",
66 " Supported listings:\n",
67 " rrdfiles List RRD file paths\n",
68 " snmphosts List SNMP hosts\n",
69 " --type=TYPE [".$selectType."] selection type\n",
70 " Supported types:\n",
71 " collector Collector leaves\n",
72 " readonly Read-only leaves\n",
73 " all All of above\n",
74 " --help this help message\n";
79 if( not Torrus::SiteConfig::treeExists( $tree ) )
81 Error('Tree ' . $tree . ' does not exist');
85 &Torrus::DB::setSafeSignalHandlers();
87 my $config_tree = new Torrus::ConfigTree( -TreeName => $tree, -Wait => 1 );
88 if( not defined( $config_tree ) )
93 my $initToken = $config_tree->token( $initPath );
94 if( not defined( $initToken ) )
96 Error('No such subtree: ' . $initPath);
103 if( $selectType eq 'all' )
105 foreach my $type ( keys %{$listingsSupported{$listWhat}} )
109 $listParams->{$type} = 1;
115 $listParams->{$selectType} = 1;
118 pickup_data( $config_tree, $initToken, $listing, $listWhat, $listParams );
120 foreach my $item ( sort keys %{$listing} )
129 my $config_tree = shift;
132 my $listWhat = shift;
133 my $listParams = shift;
135 foreach my $ctoken ( $config_tree->getChildren( $token ) )
137 &Torrus::DB::checkInterrupted();
139 if( $config_tree->isSubtree( $ctoken ) )
141 pickup_data( $config_tree, $ctoken,
142 $listing, $listWhat, $listParams );
144 elsif( $config_tree->isLeaf( $ctoken ) )
146 if( $listWhat eq 'rrdfiles' and
149 $listParams->{'collector'} and
150 $config_tree->getNodeParam( $ctoken, 'ds-type' ) eq
152 $config_tree->getNodeParam( $ctoken, 'storage-type' ) eq
156 $listParams->{'readonly'} and
157 $config_tree->getNodeParam( $ctoken, 'ds-type' ) eq
159 $config_tree->getNodeParam( $ctoken, 'leaf-type' ) eq
166 $config_tree->getNodeParam( $ctoken, 'data-file' );
168 $config_tree->getNodeParam( $ctoken, 'data-dir' );
169 $listing->{$datadir . '/' . $datafile} = 1;
171 elsif( $listWhat eq 'snmphosts' and
172 $listParams->{'collector'} and
173 $config_tree->getNodeParam( $ctoken, 'ds-type' ) eq
177 $config_tree->getNodeParam( $ctoken, 'snmp-host' );
179 $config_tree->getNodeParam( $ctoken, 'snmp-object' );
181 if( defined( $host ) and length( $host ) > 0 and
182 defined( $oid ) and length( $oid ) > 0 )
184 $listing->{$host} = 1;
195 # indent-tabs-mode: nil
196 # perl-indent-level: 4