1 rizwank 1.1 #!/usr/bin/perl
2 #-----------------------------------------------------------------------------
3 # ClusterInfo AWStats plugin
4 # This plugin allow you to add information on cluster chart from
5 # a text file. Like full cluster hostname.
6 # You must create a file called clusterinfo.configvalue.txt wich contains 2
7 # columns separated by a tab char, and store it in DirData directory.
8 # First column is cluster number and second column is text you want to add.
9 #-----------------------------------------------------------------------------
10 # Perl Required Modules: None
11 #-----------------------------------------------------------------------------
12 # $Revision: 1.1 $ - $Author: eldy $ - $Date: 2004/06/11 21:34:32 $
13
14
15 # <-----
16 # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
17 #if (!eval ('require "TheModule.pm";')) { return $@?"Error: $@":"Error: Need Perl module TheModule"; }
18 # ----->
19 use strict;no strict "refs";
20
21
22 rizwank 1.1
23 #-----------------------------------------------------------------------------
24 # PLUGIN VARIABLES
25 #-----------------------------------------------------------------------------
26 # <-----
27 # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
28 # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
29 my $PluginNeedAWStatsVersion="6.2";
30 my $PluginHooksFunctions="ShowInfoCluster";
31 # ----->
32
33 # <-----
34 # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
35 use vars qw/
36 $clusterinfoloaded
37 %ClusterInfo
38 /;
39 # ----->
40
41
42
43 rizwank 1.1 #-----------------------------------------------------------------------------
44 # PLUGIN FUNCTION: Init_pluginname
45 #-----------------------------------------------------------------------------
46 sub Init_clusterinfo {
47 my $InitParams=shift;
48 my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
49
50 # <-----
51 # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
52 debug(" Plugin clusterinfo: InitParams=$InitParams",1);
53 $clusterinfoloaded=0;
54 %ClusterInfo=();
55 # ----->
56
57 return ($checkversion?$checkversion:"$PluginHooksFunctions");
58 }
59
60
61
62 #-----------------------------------------------------------------------------
63 # PLUGIN FUNCTION: ShowInfoCluster_pluginname
64 rizwank 1.1 # UNIQUE: NO (Several plugins using this function can be loaded)
65 # Function called to add additionnal columns to Cluster report.
66 # This function is called when building rows of the report (One call for each
67 # row). So it allows you to add a column in report, for example with code :
68 # print "<TD>This is a new cell</TD>";
69 # Parameters: Cluster number
70 #-----------------------------------------------------------------------------
71 sub ShowInfoCluster_clusterinfo {
72 my $param="$_[0]";
73 # <-----
74 my $filetoload='';
75 if ($param && $param ne '__title__' && ! $clusterinfoloaded) {
76 # Load clusterinfo file
77 if ($SiteConfig && open(CLUSTERINFOFILE,"$DirData/clusterinfo.$SiteConfig.txt")) { $filetoload="$DirData/clusterinfo.$SiteConfig.txt"; }
78 elsif (open(CLUSTERINFOFILE,"$DirData/clusterinfo.txt")) { $filetoload="$DirData/clusterinfo.txt"; }
79 else { error("Couldn't open ClusterInfo file \"$DirData/clusterinfo.txt\": $!"); }
80 # This is the fastest way to load with regexp that I know
81 %ClusterInfo = map(/^([^\s]+)\s+(.+)/o,<CLUSTERINFOFILE>);
82 close CLUSTERINFOFILE;
83 debug(" Plugin clusterinfo: ClusterInfo file loaded: ".(scalar keys %ClusterInfo)." entries found.");
84 $clusterinfoloaded=1;
85 rizwank 1.1 }
86 if ($param eq '__title__') {
87 print "<th>$Message[114]</th>";
88 }
89 elsif ($param) {
90 print "<td class=\"aws\">";
91 if ($ClusterInfo{$param}) { print "$ClusterInfo{$param}"; }
92 else { print " "; } # Undefined cluster info
93 print "</td>";
94 }
95 else {
96 print "<td> </td>";
97 }
98 return 1;
99 # ----->
100 }
101
102
103 1; # Do not remove this line
|