[c5c522c] | 1 | #!/usr/local/bin/perl -w |
---|
| 2 | |
---|
| 3 | use IO::Socket; |
---|
| 4 | use Fcntl; |
---|
| 5 | |
---|
| 6 | # Connect to the server... |
---|
| 7 | $remote = IO::Socket::INET->new( |
---|
| 8 | Proto => "tcp", |
---|
| 9 | PeerAddr => "localhost", |
---|
| 10 | PeerPort => "13666", |
---|
| 11 | ) |
---|
| 12 | || die "Cannot connect to LCDproc port\n"; |
---|
| 13 | |
---|
| 14 | # Make sure our messages get there right away |
---|
| 15 | $remote->autoflush(1); |
---|
| 16 | |
---|
| 17 | `sleep 1`; # Give server plenty of time to notice us... |
---|
| 18 | |
---|
| 19 | print $remote "hello\n"; |
---|
| 20 | my $lcdconnect = <$remote>; |
---|
| 21 | print $lcdconnect; |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | # Turn off blocking mode... |
---|
| 25 | fcntl($remote, F_SETFL, O_NONBLOCK); |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | # Set up some screen widgets... |
---|
| 29 | print $remote "client_set name {Test Client (Perl)}\n"; |
---|
| 30 | print $remote "screen_add pings\n"; |
---|
| 31 | print $remote "screen_set pings name {Ping Status}\n"; |
---|
| 32 | print $remote "widget_add pings title title\n"; |
---|
| 33 | print $remote "widget_set pings title {Ping Status}\n"; |
---|
| 34 | print $remote "widget_add pings one string\n"; |
---|
| 35 | print $remote "widget_add pings two string\n"; |
---|
| 36 | print $remote "widget_set pings one 1 2 {Checking machines...}\n"; |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | my ($machine, %down, %up, $i, $list); |
---|
| 40 | |
---|
| 41 | while(1) |
---|
| 42 | { |
---|
| 43 | #print "Main loop...\n"; |
---|
| 44 | # Handle input... (just spew it to the console) |
---|
| 45 | while(defined($line = <$remote>)) { |
---|
| 46 | print $line; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | undef %down; |
---|
| 50 | undef %up; |
---|
| 51 | foreach $machine ("www.yahoo.com", |
---|
| 52 | "webfoot", |
---|
| 53 | "degas", |
---|
| 54 | "cassat", |
---|
| 55 | "miro", |
---|
| 56 | "monet", |
---|
| 57 | "dali", |
---|
| 58 | "escher", |
---|
| 59 | "seurat", |
---|
| 60 | "rodin", |
---|
| 61 | "matisse", |
---|
| 62 | ) |
---|
| 63 | { |
---|
| 64 | `ping -c 1 $machine`; |
---|
| 65 | if($?) { $down{$machine} = 1; } |
---|
| 66 | else { $up{$machine} = 1; } |
---|
| 67 | } |
---|
| 68 | $i = 0; $list = ""; |
---|
| 69 | foreach $machine (keys %up) |
---|
| 70 | { |
---|
| 71 | $i++; |
---|
| 72 | $list .= "$machine, "; |
---|
| 73 | } |
---|
| 74 | print $remote "widget_set pings one 1 2 {Machines Up: $i}\n"; |
---|
| 75 | $i = 0; $list = ""; |
---|
| 76 | foreach $machine (keys %down) |
---|
| 77 | { |
---|
| 78 | $i++; |
---|
| 79 | $list .= "$machine, "; |
---|
| 80 | } |
---|
| 81 | print $remote "widget_set pings two 1 3 {Down ($i): $list}\n"; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | close ($remote) || die "close: $!"; |
---|
| 85 | exit; |
---|