Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Generating HTML from SNMP data

by submersible_toaster (Chaplain)
on Jun 16, 2003 at 00:17 UTC ( #266091=note: print w/replies, xml ) Need Help??

in reply to Generating HTML from SNMP data

Update: ++TomDLux , beat me to the punch! Signing up for the monastery is a great idea.
HTML::Template will save your bacon. Specifically its looping feature. Design the layout of a table/cell for one switch status. Insert place holders into the relevant fields, and a template loop around the whole deal.

<html> <body> <table border=3> <TMPL_LOOP switches> <tr> <td> <TMPL_VAR hostname> </td> <td> <TMPL_VAR status> </td> </tr> </TMPL_LOOP> </table> </body> </html>

Then you can feed your data into that with HTML::Template

#!/usr/bin/perl -w use strict; use Data::Dumper; use HTML::Template; my $template = HTML::Template->new( filename=>'./switch-status.tmpl' ) +; my @hosts = ( qw/ switch cisco1 cisco2 ninety nine cisco5 / ); my $info = []; foreach my $host ( @hosts ) { my $data = { hostname=> $host, status => Host2Status($host) , }; push @$info , $data; } $template->param(switches=>$info); print $template->output; sub Host2Status { my $host = shift; my $rand_status = int (rand 2)-1; my $status = ($rand_status) ? "Cool" : "Froody"; return $status; }

This code works for me , no guarantees though. The cpan documentation for HTML::Template is good. If you are familiar with creating semi-complex datastructures in perl like an array of hashes, you will have this done in _NO_ time.

I can't believe it's not psellchecked

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://266091]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2019-05-27 14:16 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (156 votes). Check out past polls.