| 1 | 1 | simandl | #!/usr/bin/env perl |
| 2 | | | |
| 3 | | | # $Id: setup.pl,v 1.11 2004/07/12 07:50:13 bernisys Exp $ |
| 4 | | | |
| 5 | | | # include PERL libraries |
| 6 | | | use strict; |
| 7 | | | use warnings; |
| 8 | | | use diagnostics; |
| 9 | | | |
| 10 | | | # include HotSaNIC libraries |
| 11 | | | use lib "../../lib"; |
| 12 | | | use lib "./platform"; |
| 13 | | | use HotSaNICparser; |
| 14 | | | use HotSaNICshellio; |
| 15 | | | use HotSaNIClog; |
| 16 | | | use common; |
| 17 | | | |
| 18 | | | $|=1; |
| 19 | | | |
| 20 | | | (my $VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/; |
| 21 | | | (my $IDENTIFIER = '$Id: setup.pl,v 1.11 2004/07/12 07:50:13 bernisys Exp $') =~ s/.*,v (.*) \$/$1/; |
| 22 | | | |
| 23 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
| 24 | | | my %MODCONF=HotSaNICmod::common::configure(); |
| 25 | | | my $OUTFILE="settings.new"; |
| 26 | | | if ( ! -e "settings" ) { $OUTFILE="settings"; } |
| 27 | | | open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n"; |
| 28 | | | |
| 29 | | | if (! @{$MODCONF{APP}}) { @{$MODCONF{APP}}=get_apps(); } |
| 30 | | | if (@{$MODCONF{APP}}) { $MODCONF{APP}="APP=\"".join("\"\nAPP=\"",@{$MODCONF{APP}})."\""; } |
| 31 | | | else { $MODCONF{APP}=""; } |
| 32 | | | |
| 33 | | | print OUTFILE "# SHORT DESCRIPTION |
| 34 | | | # |
| 35 | | | # entries have the format: |
| 36 | | | # APP=<process>,<description> |
| 37 | | | # |
| 38 | | | # <process> the name of the process to count as shown in 'ps' |
| 39 | | | # (May also be 'SNMP:host:community:name') |
| 40 | | | # |
| 41 | | | # Note: Be sure you have no '_' in host or community, because this will |
| 42 | | | # result in errors during sampeling and converting data. |
| 43 | | | # |
| 44 | | | # <description> a brief description for the webpage |
| 45 | | | # |
| 46 | | | # Example: |
| 47 | | | # APP=httpd,Apache |
| 48 | | | # APP=SNMP:arthur:public:sshd,sshd\@arthur |
| 49 | | | # |
| 50 | | | $MODCONF{APP} |
| 51 | | | "; |
| 52 | | | |
| 53 | | | close OUTFILE; |
| 54 | | | |
| 55 | | | if ($OUTFILE eq "settings.new") { |
| 56 | | | HotSaNICparser::backup_file("settings"); |
| 57 | | | rename "settings.new","settings"; |
| 58 | | | } |
| 59 | | | |
| 60 | | | print "Please check the settings file and adapt it to satisfy your needs.\n"; |
| 61 | | | |
| 62 | | | sub get_apps { |
| 63 | | | my @apps=(); |
| 64 | | | my %apps=(); |
| 65 | | | open RESULT,"ps -axc|"; |
| 66 | | | $_=<RESULT>; #strip header line |
| 67 | | | while (<RESULT>) { |
| 68 | | | chomp; |
| 69 | | | s/ *$//; # strip spaces |
| 70 | | | s/^.* //; # only need last word |
| 71 | | | $apps{$_}++; |
| 72 | | | } |
| 73 | | | foreach (sort keys %apps) { |
| 74 | | | printf "%-20s (running %d times now) - ",$_,$apps{$_}; |
| 75 | | | my $result=HotSaNICshellio::askyesno("Use this item?","n"); |
| 76 | | | push @apps,"$_,$_" if $result eq "y"; |
| 77 | | | } |
| 78 | | | close RESULT; |
| 79 | | | return @apps; |
| 80 | | | } |
| 81 | | | |