![]() ![]() |
hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/env perl# $Id: setup.pl,v 1.11 2004/07/12 07:50:13 bernisys Exp $# include PERL librariesuse strict;use warnings;use diagnostics;# include HotSaNIC librariesuse lib "../../lib";use lib "./platform";use HotSaNICparser;use HotSaNICshellio;use HotSaNIClog;use common;$|=1;(my $VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/;(my $IDENTIFIER = '$Id: setup.pl,v 1.11 2004/07/12 07:50:13 bernisys Exp $') =~ s/.*,v (.*) \$/$1/;my $MODNAME=HotSaNICparser::get_module_name();my %MODCONF=HotSaNICmod::common::configure();my $OUTFILE="settings.new";if ( ! -e "settings" ) { $OUTFILE="settings"; }open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n";if (! @{$MODCONF{APP}}) { @{$MODCONF{APP}}=get_apps(); }if (@{$MODCONF{APP}}) { $MODCONF{APP}="APP=\"".join("\"\nAPP=\"",@{$MODCONF{APP}})."\""; }else { $MODCONF{APP}=""; }print OUTFILE "# SHORT DESCRIPTION## entries have the format:# APP=<process>,<description>## <process> the name of the process to count as shown in 'ps'# (May also be 'SNMP:host:community:name')## Note: Be sure you have no '_' in host or community, because this will# result in errors during sampeling and converting data.## <description> a brief description for the webpage## Example:# APP=httpd,Apache# APP=SNMP:arthur:public:sshd,sshd\@arthur#$MODCONF{APP}";close OUTFILE;if ($OUTFILE eq "settings.new") {HotSaNICparser::backup_file("settings");rename "settings.new","settings";}print "Please check the settings file and adapt it to satisfy your needs.\n";sub get_apps {my @apps=();my %apps=();open RESULT,"ps -axc|";$_=<RESULT>; #strip header linewhile (<RESULT>) {chomp;s/ *$//; # strip spacess/^.* //; # only need last word$apps{$_}++;}foreach (sort keys %apps) {printf "%-20s (running %d times now) - ",$_,$apps{$_};my $result=HotSaNICshellio::askyesno("Use this item?","n");push @apps,"$_,$_" if $result eq "y";}close RESULT;return @apps;}