| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
#********************************************************************* |
| 4 |
# |
| 5 |
# fai-monitor-gui: graphical FAI monitor daemon |
| 6 |
# |
| 7 |
# This script is part of FAI (Fully Automatic Installation) |
| 8 |
# Copyright (C) 2007-2016 Thomas Lange, [email protected] |
| 9 |
# Universitaet zu Koeln |
| 10 |
# |
| 11 |
#********************************************************************* |
| 12 |
# This program is free software; you can redistribute it and/or modify |
| 13 |
# it under the terms of the GNU General Public License as published by |
| 14 |
# the Free Software Foundation; either version 2 of the License, or |
| 15 |
# (at your option) any later version. |
| 16 |
# |
| 17 |
# This program is distributed in the hope that it will be useful, but |
| 18 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
# General Public License for more details. |
| 21 |
# |
| 22 |
# A copy of the GNU General Public License is available as |
| 23 |
# '/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution |
| 24 |
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You |
| 25 |
# can also obtain it by writing to the Free Software Foundation, Inc., |
| 26 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 27 |
#********************************************************************* |
| 28 |
|
| 29 |
# TODO: Add support for TASKERROR |
| 30 |
|
| 31 |
use strict; |
| 32 |
use Getopt::Std; |
| 33 |
use Tk; |
| 34 |
use Tk::HList; |
| 35 |
use Tk::ItemStyle; |
| 36 |
#use Tk::Balloon; |
| 37 |
|
| 38 |
my $tcounter; |
| 39 |
my $n; |
| 40 |
our ($opt_s,$font1,$font2,$icondir,$top,$defstyle,$hlist,$backcolor,$forecolor,$headercolor,$headerstyle,$input); |
| 41 |
our(%icon,%task,%row); |
| 42 |
|
| 43 |
my $debug = 0; |
| 44 |
|
| 45 |
#@tasklist = qw/hostname confdir defclass action partition mountdisks extrbase debconf repository instsoft configure chboot savelog faiend reboot/; |
| 46 |
my @tasklist = qw/hostname confdir defclass partition extrbase repository instsoft configure tests savelog faiend reboot/; |
| 47 |
$tasklist[0] = ' 'x15 . 'hostname'. ' 'x15; |
| 48 |
|
| 49 |
|
| 50 |
my $rowcount = 0; |
| 51 |
my %message = ( 'TASKBEGIN' => 'BEG', 'TASKEND' => 'END'); |
| 52 |
|
| 53 |
# - - - - - - - - - - - - - - - - - - |
| 54 |
sub getinp { |
| 55 |
|
| 56 |
my $line = <$input>; |
| 57 |
return 0 if $line =~/^FAI monitoring daemon start/; # ignore start up messages from fai-monitor |
| 58 |
return 0 if $line =~/Disabling pxelinux configuration/; |
| 59 |
return 0 if $line =~/^VARIABLE /; |
| 60 |
warn "INPUT received $line" if $debug; |
| 61 |
hostentry($line); |
| 62 |
return 0; |
| 63 |
} |
| 64 |
# - - - - - - - - - - - - - - - - - - |
| 65 |
sub mkgraphics { |
| 66 |
|
| 67 |
#Style entries |
| 68 |
|
| 69 |
$icon{'success'} = $top->Photo(-file=>"$icondir/ok.gif"); |
| 70 |
$icon{'minor'} = $top->Photo(-file=>"$icondir/minor.gif"); |
| 71 |
$icon{'warning'} = $top->Photo(-file=>"$icondir/warning.gif"); |
| 72 |
$icon{'fail'} = $top->Photo(-file=>"$icondir/fail.gif"); |
| 73 |
$icon{'begin'} = $top->Photo(-file=>"$icondir/begin.gif"); |
| 74 |
$icon{'host'} = $top->Photo(-file=>"$icondir/bar.gif"); |
| 75 |
|
| 76 |
$defstyle = $hlist->ItemStyle("imagetext", |
| 77 |
-foreground => $forecolor, |
| 78 |
-background => $backcolor, |
| 79 |
-font => $font2, |
| 80 |
); |
| 81 |
|
| 82 |
$headerstyle = $hlist->ItemStyle("imagetext", |
| 83 |
-bg=>$backcolor, |
| 84 |
-fg=>$headercolor, |
| 85 |
-font=>$font1 |
| 86 |
); |
| 87 |
|
| 88 |
# not yet used |
| 89 |
# $balloonstatus = $top->Balloon(); |
| 90 |
# $balloonstatus->attach($top,-msg=>"status",-balloonposition=>"mouse"); |
| 91 |
} |
| 92 |
# - - - - - - - - - - - - - - - - - - |
| 93 |
sub icon { |
| 94 |
|
| 95 |
my ($host,$task,$iname) = @_; |
| 96 |
|
| 97 |
$hlist->itemCreate($row{$host}, $task{$task}, -text=>'' ,-itemtype=>"imagetext",-image=>$icon{$iname}); |
| 98 |
$hlist->itemConfigure($row{$host}, $task{$task}, -itemtype=>"imagetext",-style=>$defstyle); |
| 99 |
} |
| 100 |
# - - - - - - - - - - - - - - - - - - |
| 101 |
sub hostentry { |
| 102 |
|
| 103 |
my $str = shift(@_); |
| 104 |
my ($host,$startstop,$task,$code) = split(/\s+/,$str); |
| 105 |
my $message; |
| 106 |
|
| 107 |
warn "hostentry: $host $startstop $task $code\n" if $debug; |
| 108 |
|
| 109 |
unless (exists $row{$host}) { |
| 110 |
# add host, first column |
| 111 |
$row{$host} = $rowcount++; |
| 112 |
|
| 113 |
$hlist->add($row{$host},-state=>"disabled"); |
| 114 |
$hlist->itemCreate($row{$host}, 0, |
| 115 |
-itemtype => "imagetext", |
| 116 |
-text => $host, |
| 117 |
-style=>$headerstyle, |
| 118 |
-image=>$icon{'host'}); |
| 119 |
} |
| 120 |
|
| 121 |
# remove old information when doing an reinstallation |
| 122 |
if ($startstop eq 'check') { |
| 123 |
foreach (1 .. $#tasklist) { |
| 124 |
warn "row: $row{$host} nr.: $_\n" if $debug; |
| 125 |
$hlist->itemCreate($row{$host}, $_, -text => ''); |
| 126 |
} |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
warn "create: $row{$host} | $task{$task} | $startstop $message{$startstop} $code\n" if $debug; |
| 131 |
unless (exists $task{$task}) { |
| 132 |
# do not show unknown tasks |
| 133 |
return; |
| 134 |
} |
| 135 |
|
| 136 |
$message = ($startstop =~ /TASKEND/) ? $message="$message{$startstop} $code": $message{$startstop}; |
| 137 |
|
| 138 |
($message eq 'BEG') && icon($host,$task,'begin'); |
| 139 |
if ($message =~ /END (\d+)/) { |
| 140 |
my $ret = $1; # save error code |
| 141 |
($ret < 300) and icon($host,$task,'success'),return; |
| 142 |
($ret < 500) and icon($host,$task,'warning'),return; |
| 143 |
($ret < 700) and icon($host,$task,'minor'),return; |
| 144 |
icon($host,$task,'fail'); |
| 145 |
} |
| 146 |
|
| 147 |
} |
| 148 |
# - - - - - - - - - - - - - - - - - - |
| 149 |
sub usage { |
| 150 |
|
| 151 |
print << "EOF"; |
| 152 |
fai-monitor-gui, graphical FAI monitor daemon |
| 153 |
|
| 154 |
Copyright (C) 2007-2016 by Thomas Lange |
| 155 |
|
| 156 |
Usage: fai-monitor | fai-monitor-gui - |
| 157 |
|
| 158 |
-s Use smaller icons. |
| 159 |
|
| 160 |
EOF |
| 161 |
exit 0; |
| 162 |
} |
| 163 |
# - - - - - - - - - - - - - - - - - - |
| 164 |
# main program |
| 165 |
|
| 166 |
getopts('s') || usage; |
| 167 |
|
| 168 |
if ($opt_s) { |
| 169 |
$font1="Sans 13"; |
| 170 |
$font2="Sans 7"; |
| 171 |
$icondir='/usr/share/fai/pixmaps/small'; |
| 172 |
} else { |
| 173 |
$font1="Sans 15"; |
| 174 |
$font2="Sans 10"; |
| 175 |
$icondir='/usr/share/fai/pixmaps'; |
| 176 |
} |
| 177 |
|
| 178 |
$backcolor="#76716f"; |
| 179 |
$forecolor="#ffffff"; |
| 180 |
$headercolor="#ffffff"; |
| 181 |
|
| 182 |
open($input, "<$ARGV[0]") or die "Can't open input file. $@"; |
| 183 |
|
| 184 |
$top = new MainWindow; |
| 185 |
#$top->configure(-background=> $backcolor); |
| 186 |
$hlist = $top->Scrolled("HList", |
| 187 |
-header => 1, |
| 188 |
-font => $font2, |
| 189 |
-columns => $#tasklist+1, |
| 190 |
-scrollbars => 'oe', |
| 191 |
-width => 102, |
| 192 |
-height => 20, |
| 193 |
-selectbackground => $backcolor, |
| 194 |
-background=> $backcolor, |
| 195 |
-selectborderwidth=>0, |
| 196 |
-selectmode=>'single', |
| 197 |
-highlightthickness=>0, |
| 198 |
-relief=>'flat', |
| 199 |
-borderwidth=>0, |
| 200 |
)->pack(-expand => 1, -fill => 'both'); |
| 201 |
|
| 202 |
mkgraphics; |
| 203 |
$top->fileevent($input,'readable', [\&getinp]); |
| 204 |
|
| 205 |
foreach (@tasklist) { |
| 206 |
$hlist->header('create', $n++, -text => $_, |
| 207 |
-headerbackground=>"#aabbcc", |
| 208 |
-borderwidth=>1, |
| 209 |
-relief=>"groove"); |
| 210 |
$task{$_} = $tcounter++; |
| 211 |
} |
| 212 |
|
| 213 |
MainLoop(); |