1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | use warnings; |
3 | | | use diagnostics; |
4 | | | |
5 | | | use lib "../../lib"; |
6 | | | use HotSaNICparser; |
7 | | | |
8 | | | # read global settings |
9 | | | # |
10 | | | $MODNAME=lc HotSaNICparser::get_module_name(); |
11 | | | |
12 | | | %CONFIG=HotSaNICparser::get_config("../.."); |
13 | | | $IMAGEFORMAT=$CONFIG{"IMAGEFORMAT"}; |
14 | | | $REFRESH=$CONFIG{"REFRESH"}; |
15 | | | $REFRESH=0 if !defined $REFRESH; |
16 | | | |
17 | | | # read module-specific settings |
18 | | | # |
19 | | | |
20 | | | # evaluate number of CPUs |
21 | | | # |
22 | | | opendir DIR,"rrd"; |
23 | | | @DBs = grep /^[^.].*/, readdir DIR; |
24 | | | closedir DIR; |
25 | | | foreach (@DBs) { chomp; s/\.rrd//g; |
26 | | | push @db,$_; |
27 | | | if (/mem/) { s/mem/swap/g; push @db,$_; } |
28 | | | } |
29 | | | |
30 | | | @db=sort(@db); |
31 | | | |
32 | | | # build time-based .html files |
33 | | | # |
34 | | | foreach $index ("hour","week") { |
35 | | | open (FILE,">index/$index.html"); |
36 | | | print FILE "<html>\n"; |
37 | | | if ($REFRESH > 0) { |
38 | | | print FILE "<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> |
39 | | | <META HTTP-EQUIV=\"Refresh\" CONTENT=\"$REFRESH\"> |
40 | | | <META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
41 | | | } |
42 | | | print FILE "<body>\n<table>\n"; |
43 | | | |
44 | | | for (@db) { |
45 | | | ($link_name = $_) =~ s/_/:/; |
46 | | | print FILE "<tr><td><a href=\"$_.html\"><img src=\"$_-",$index,".",$IMAGEFORMAT,"\"></a></td>\n |
47 | | | <td valign=top><a href=\"proc.html\"><h2>$link_name</h2></a></td></tr>\n"; |
48 | | | } |
49 | | | |
50 | | | print FILE "</table>\n</body>\n</html>\n"; |
51 | | | close FILE; |
52 | | | } |
53 | | | |
54 | | | $count = 0; |
55 | | | for (@db) { $count += 1 if /cpu/; } |
56 | | | |
57 | | | open (IDXFILE,">idxdata"); |
58 | | | if ($count>1) { print IDXFILE "$count\n"; } |
59 | | | |
60 | | | print IDXFILE "0## <td colspan=".2*$count." align=center> <font size=\"+3\">",$MODNAME,"</font><br> |
61 | | | 0## <a href=\"",$MODNAME,"/hour.html\">hour</a> |
62 | | | 0## <a href=\"",$MODNAME,"/week.html\">week</a><br> |
63 | | | 0## <hr width=90%> |
64 | | | 0## </td>"; |
65 | | | |
66 | | | @res = grep /proc/, @db; |
67 | | | for (@res) { |
68 | | | ($link_name = $_) =~ s/_/:/; |
69 | | | print IDXFILE " |
70 | | | 1## <td><a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a></td> |
71 | | | 1## <td valign=top><a href=\"",$MODNAME,"/$_.html\">$link_name</a></td>"; |
72 | | | } |
73 | | | $num=@res; |
74 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n1## <td></td><td></td>";} |
75 | | | |
76 | | | @res = grep /cpu/, @db; |
77 | 27 | simandl | print IDXFILE " |
78 | | | 2## <td>"; |
79 | 1 | simandl | for (@res) { |
80 | | | ($link_name = $_) =~ s/_/:/; |
81 | | | print IDXFILE " |
82 | 27 | simandl | 2## <a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a> |
83 | | | 2## <a href=\"",$MODNAME,"/$_.html\">$link_name</a>"; |
84 | 1 | simandl | } |
85 | 27 | simandl | print IDXFILE " |
86 | | | 2## </td>"; |
87 | | | for ($i = 0; $i < 2 * @res - 1; ++$i) { |
88 | | | print IDXFILE " |
89 | | | 2## <td></td>"; |
90 | | | } |
91 | 1 | simandl | $num=@res; |
92 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n2## <td></td><td></td>";} |
93 | | | |
94 | | | @res = grep /load/, @db; |
95 | | | for (@res) { |
96 | | | ($link_name = $_) =~ s/_/:/; |
97 | | | print IDXFILE " |
98 | | | 3## <td><a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a></td> |
99 | | | 3## <td valign=top><a href=\"",$MODNAME,"/$_.html\">$link_name</a></td>"; |
100 | | | } |
101 | | | $num=@res; |
102 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n3## <td></td><td></td>";} |
103 | | | |
104 | | | @res = grep /mem/, @db; |
105 | | | for (@res) { |
106 | | | ($link_name = $_) =~ s/_/:/; |
107 | | | print IDXFILE " |
108 | | | 4## <td><a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a></td> |
109 | | | 4## <td valign=top><a href=\"",$MODNAME,"/$_.html\">$link_name</a></td>"; |
110 | | | } |
111 | | | $num=@res; |
112 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n4## <td></td><td></td>";} |
113 | | | |
114 | | | @res = grep /swap/, @db; |
115 | | | for (@res) { |
116 | | | ($link_name = $_) =~ s/_/:/; |
117 | | | print IDXFILE " |
118 | | | 5## <td><a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a></td> |
119 | | | 5## <td valign=top><a href=\"",$MODNAME,"/$_.html\">$link_name</a></td>"; |
120 | | | } |
121 | | | $num=@res; |
122 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n5## <td></td><td></td>";} |
123 | | | |
124 | | | @res = grep /users/, @db; |
125 | | | for (@res) { |
126 | | | ($link_name = $_) =~ s/_/:/; |
127 | | | print IDXFILE " |
128 | | | 6## <td><a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a></td> |
129 | | | 6## <td valign=top><a href=\"",$MODNAME,"/$_.html\">$link_name</a></td>"; |
130 | | | } |
131 | | | $num=@res; |
132 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n6## <td></td><td></td>";} |
133 | | | |
134 | | | @res = grep /irq/, @db; |
135 | | | for (@res) { |
136 | | | print IDXFILE " |
137 | | | 7## <td><a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a></td> |
138 | | | 7## <td valign=top><a href=\"",$MODNAME,"/$_.html\">interrupts</a></td>"; |
139 | | | } |
140 | | | $num=@res; |
141 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n7## <td></td><td></td>";} |
142 | | | |
143 | | | @res = grep /uptime/, @db; |
144 | | | for (@res) { |
145 | | | print IDXFILE " |
146 | | | 8## <td><a href=\"",$MODNAME,"/$_.html\"><img src=\"system/thumb-$_.",$IMAGEFORMAT,"\"></a></td> |
147 | | | 8## <td valign=top><a href=\"",$MODNAME,"/$_.html\">uptime</a></td>"; |
148 | | | } |
149 | | | $num=@res; |
150 | | | for ($nn=$num;$nn<$count;$nn++) { print IDXFILE "\n8## <td></td><td></td>";} |
151 | | | |
152 | | | close IDXFILE; |
153 | | | |
154 | | | foreach $index (@db) { |
155 | | | print "writing $index\n"; |
156 | | | open (FILE,">index/$index.html"); |
157 | | | print FILE "<html>\n"; |
158 | | | if ($REFRESH > 0) { |
159 | | | print FILE "<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> |
160 | | | <META HTTP-EQUIV=\"Refresh\" CONTENT=\"$REFRESH\"> |
161 | | | <META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
162 | | | } |
163 | | | print FILE "<body>\n"; |
164 | | | if ( index ($index,"uptime") <0 ) { print FILE "<img src=\"",$index,"-hour.",$IMAGEFORMAT,"\">\n"; } |
165 | | | print FILE "<img src=\"",$index,"-day.",$IMAGEFORMAT,"\">\n"; |
166 | | | print FILE "<img src=\"",$index,"-week.",$IMAGEFORMAT,"\">\n"; |
167 | | | print FILE "<img src=\"",$index,"-month.",$IMAGEFORMAT,"\">\n"; |
168 | | | print FILE "<img src=\"",$index,"-year.",$IMAGEFORMAT,"\">\n</body>\n</html>\n"; |
169 | | | close FILE; |
170 | | | } |
171 | | | |