jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [modules/] [apps/] [setup.pl] - Blame information for rev 18

 

Line No. Rev Author Line
11simandl#!/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
6use strict;
7use warnings;
8use diagnostics;
9 
10# include HotSaNIC libraries
11use lib "../../lib";
12use lib "./platform";
13use HotSaNICparser;
14use HotSaNICshellio;
15use HotSaNIClog;
16use 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 
23my $MODNAME=HotSaNICparser::get_module_name();
24my %MODCONF=HotSaNICmod::common::configure();
25my $OUTFILE="settings.new";
26if ( ! -e "settings" ) { $OUTFILE="settings"; }
27open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n";
28 
29if (! @{$MODCONF{APP}}) { @{$MODCONF{APP}}=get_apps(); }
30if (@{$MODCONF{APP}}) { $MODCONF{APP}="APP=\"".join("\"\nAPP=\"",@{$MODCONF{APP}})."\""; }
31else { $MODCONF{APP}=""; }
32 
33print 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 
53close OUTFILE;
54 
55if ($OUTFILE eq "settings.new") {
56 HotSaNICparser::backup_file("settings");
57 rename "settings.new","settings";
58 }
59 
60print "Please check the settings file and adapt it to satisfy your needs.\n";
61 
62sub 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 

Powered by WebSVN 2.2.1