| 1 | 1 | simandl | #!/usr/bin/env perl |
| 2 | | | |
| 3 | | | # $Id: setup.pl,v 1.13 2004/07/12 07:50:16 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.13 $') =~ s/.*(\d+\.\d+).*/$1/; |
| 21 | | | (my $IDENTIFIER = '$Id: setup.pl,v 1.13 2004/07/12 07:50:16 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{DEV}}) { @{$MODCONF{DEV}}=get_interfaces(); } |
| 30 | | | if (@{$MODCONF{DEV}}) { $MODCONF{DEV}="DEV=\"".join("\"\nDEV=\"",@{$MODCONF{DEV}})."\""; } |
| 31 | | | else { $MODCONF{DEV}=""; } |
| 32 | | | |
| 33 | | | print OUTFILE "# SHORT DESCRIPTION |
| 34 | | | # |
| 35 | | | # Which kind of legend shall be used |
| 36 | | | # set GRAPH_BASE=\"bytes\" to display all values in bytes/s |
| 37 | | | # set GRAPH_BASE=\"bits\" to display all values in bits/s |
| 38 | | | # |
| 39 | | | # This item was previously named \"STYLE\" |
| 40 | | | # |
| 41 | | | GRAPH_BASE=\"$MODCONF{GRAPH_BASE}\" |
| 42 | | | |
| 43 | | | # Shall input and output traffic be swaped ? |
| 44 | | | # (possible values meaning \"yes\" are: \"yes\" \"true\" \"1\") |
| 45 | | | # |
| 46 | | | SWAPIO=\"$MODCONF{SWAPIO}\" |
| 47 | | | |
| 48 | | | # Configure graph layout |
| 49 | | | # |
| 50 | | | # GRAPH_MIN sets the lower border |
| 51 | | | # GRAPH_MAX sets the upper border |
| 52 | | | # GRAPH_RIGID defines wether the borders may be crossed or not |
| 53 | | | # |
| 54 | | | # if you want all graphs to be plotted from -200 up to 2000, no matter |
| 55 | | | # wether the graph contains higher or lower values than configured, you |
| 56 | | | # set the following: |
| 57 | | | # |
| 58 | | | # GRAPH_MIN=\"-200\" |
| 59 | | | # GRAPH_MAX=\"2000\" |
| 60 | | | # GRAPH_RIGID=\"true\" |
| 61 | | | # |
| 62 | | | # if you set GRAPH_RIGID=\"false\", the graphs will be automatically |
| 63 | | | # scaled if higher / lower values have to be plotted. |
| 64 | | | # |
| 65 | | | # These three options were previously configured via the \"SCALE\" option |
| 66 | | | # |
| 67 | | | GRAPH_MIN=\"$MODCONF{GRAPH_MIN}\" |
| 68 | | | GRAPH_MAX=\"$MODCONF{GRAPH_MAX}\" |
| 69 | | | GRAPH_RIGID=\"$MODCONF{GRAPH_RIGID}\" |
| 70 | | | |
| 71 | | | # Configure one line for each device that shall be sampled: |
| 72 | | | # |
| 73 | | | # DEV=<device>,<max bytes/s input>,<max bytes/s output>,<description> |
| 74 | | | # |
| 75 | | | # <device> is the network-device you like to sample |
| 76 | | | # |
| 77 | | | # for SNMP queries the <device> entry has the following format: |
| 78 | | | # |
| 79 | | | # SNMP:<host>:<community>:<interface> |
| 80 | | | # |
| 81 | | | # <host> is the name or the IP of the host you want to query |
| 82 | | | # |
| 83 | | | # <community> self explaining (for newbies: the community acts almost |
| 84 | | | # like a \"password\" for SNMP) |
| 85 | | | # |
| 86 | | | # <interface> the name of the interface on the remote-host |
| 87 | | | # |
| 88 | | | # Examples: |
| 89 | | | # |
| 90 | | | # DEV=\"eth0,12500000,12500000,100 MBit ethernet\" |
| 91 | | | # DEV=\"SNMP:192.168.1.1:public:eth0,12500000,12500000,100 MBit ethernet via SNMP\" |
| 92 | | | # DEV=\"SNMP:cisco.my.net:public:Serial0/0,12500000,12500000,some line on a Cisco\" |
| 93 | | | # |
| 94 | | | $MODCONF{DEV} |
| 95 | | | "; |
| 96 | | | close OUTFILE; |
| 97 | | | |
| 98 | | | if ($OUTFILE eq "settings.new") { |
| 99 | | | HotSaNICparser::backup_file("settings"); |
| 100 | | | rename "settings.new","settings"; |
| 101 | | | } |
| 102 | | | |
| 103 | | | print "Please check the settings file and adapt it to satisfy your needs. |
| 104 | | | If you have any interfaces other than 100 MBit, please change the |
| 105 | | | corrosponding default values. |
| 106 | | | Maybe there are some additional interfaces or SNMP hosts you want |
| 107 | | | to query.\n"; |
| 108 | | | |
| 109 | | | |
| 110 | | | sub get_interfaces { |
| 111 | | | my @devs=(); |
| 112 | | | if (index($^O,"bsd") >=0) { |
| 113 | | | open OUTPUT,"ifconfig -l -u| fmt -1 |"; |
| 114 | | | while (<OUTPUT>) { |
| 115 | | | chomp; |
| 116 | | | my $input=lc HotSaNICshellio::askyesno("Use $_?","n"); |
| 117 | | | if ($input eq "y") { push @devs,"$_,12500000,12500000,100 MBit ethernet"; } |
| 118 | | | } |
| 119 | | | close OUTPUT; |
| 120 | | | } |
| 121 | | | else { |
| 122 | | | open LIST,"ifconfig|"; |
| 123 | | | while (<LIST>) { |
| 124 | | | if (/^[^\s]/) { |
| 125 | | | (my $interface)=split; |
| 126 | | | my $input=lc HotSaNICshellio::askyesno("Use $interface?","n"); |
| 127 | | | if ($input eq "y") { push @devs,"$interface,12500000,12500000,100 MBit ethernet"; } |
| 128 | | | } |
| 129 | | | } |
| 130 | | | } |
| 131 | | | return @devs; |
| 132 | | | } |
| 133 | | | |