Torna indietro   Hardware Upgrade Forum > Software > Linux, Unix, OS alternativi

Kindle Scribe Colorsoft: riduce le cornici e diventa a colori, ma il prezzo è alto
Kindle Scribe Colorsoft: riduce le cornici e diventa a colori, ma il prezzo è alto
Amazon porta i colori sul suo Kindle da scrittura più grande: schermo Colorsoft a 11 pollici, processore quad-core, penna premium più reattiva e strumenti IA per le note, sono le note salienti. Il salto di prezzo rispetto al modello in bianco e nero si fa sentire, anche se la percezione è quella di trovarsi di fronte a un prodotto di fascia altissima, per veri appassionati
L'IA cambia tutte le regole della sicurezza tra vulnerabilità e sorveglianza. Intervista al CEO di Proofpoint
L'IA cambia tutte le regole della sicurezza tra vulnerabilità e sorveglianza. Intervista al CEO di Proofpoint
Abbiamo intervistato Sumit Dhawan, CEO di Proofpoint, per capire come stia cambiando il mondo della sicurezza con l'avvento dell'intelligenza artificiale e con il ritmo sempre più serrato a cui vengono trovate vulnerabilità nel software. Un problema significativo, che richiederà del tempo per essere risolto (o quantomeno arginato)
L'Europa conta nella tecnologia e può essere autonoma. Cosa si è detto al Nextcloud Summit 2026
L'Europa conta nella tecnologia e può essere autonoma. Cosa si è detto al Nextcloud Summit 2026
La parola d'ordine al Nextcloud Summit 2026, che si è tenuto a Monaco, è stata "sovranità". Non come è spesso usato questo termine in politica ma, al contrario, come capacità positiva di decidere il proprio destino tecnologico, con modalità collaborative e aperte. L'Europa dice già molto nel mondo open source, che viene visto come mezzo per ottenere la tanto agognata autonomia digitale
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 18-05-2011, 16:14   #1
lypo
Member
 
L'Avatar di lypo
 
Iscritto dal: Jun 2010
Città: prov. Parma
Messaggi: 168
Gestione notifiche via mail con Nagios

Ho già configurato Nagios in modo che mi arrivino notifiche via mail quando un servizio va in stato critico.

Ora mi servirebbe questo:
mandare una mail ad un orario determinato del giorno con la situazione istantanea di tutti i host/servizi sia in stato Critical, Warning e Ok.
E' possibile?

So che basterebbe aprire l'interfaccia web del programma per avere subito la situazione sotto gli occhi ma a me servirebbe mandare una mail riassuntiva di tutti i servizi.

Grazie.
lypo è offline   Rispondi citando il messaggio o parte di esso
Old 18-05-2011, 20:26   #2
Gimli[2BV!2B]
Senior Member
 
L'Avatar di Gimli[2BV!2B]
 
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
Hai visto la sezione exchange del sito ufficiale?

In particolare direi che la categoria Reporting dovrebbe fare al caso tuo.

Di questi quello che, da non utilizzatore Nagios, mi sembra più specializzato al solo invio di brevi report via mail a tempi prefissati è Nagios Email Reporter.
Ha anche un'opzione per integrare il css nel corpo della mail per soddisfare client email un po' particolari come Lotus Notes.

Certo, come precisato, è un script privo di installazione da editare per impostare i propri parametri, ma il codice mi sembra ordinato e ben scritto.
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...)
Gimli[2BV!2B] è offline   Rispondi citando il messaggio o parte di esso
Old 19-05-2011, 16:59   #3
lypo
Member
 
L'Avatar di lypo
 
Iscritto dal: Jun 2010
Città: prov. Parma
Messaggi: 168
Grazie mille!

Mi ero calato in vari tentativi e non avevo pensato di guardare lì.

Ora modifico lo script secondo le mie esigenze dato che non soddisfa al 100% le richieste a cui devo rispondere.

Dopo un opportuno settaggio da linea di comando faccio:

./nagios-reporter.v131.pl [email protected] --type=daily

e mi arriva puntuale la mail.

Ora non mi resta che ordinare l'esecuzione script ad un determinato orario del giorno.
(cosa che devo ancora capire...)

Grazie mille ancora!
lypo è offline   Rispondi citando il messaggio o parte di esso
Old 19-05-2011, 20:00   #4
Gimli[2BV!2B]
Senior Member
 
L'Avatar di Gimli[2BV!2B]
 
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
Perfetto, vengono bene le mail? Potrei anche suggerirlo all'ufficio IT, mi pare di ricordare che da qualche tempo stanno utilizzando Nagios e ne sembrano soddisfatti.

Per pianificare l'esecuzione, solitamente, si utilizza il demone "del tempo" cron, impostando opportunamente crontab.
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...)
Gimli[2BV!2B] è offline   Rispondi citando il messaggio o parte di esso
Old 23-05-2011, 13:57   #5
lypo
Member
 
L'Avatar di lypo
 
Iscritto dal: Jun 2010
Città: prov. Parma
Messaggi: 168
Scusa il ritardo.

Le notifiche che arrivano via mail risultano incolonnate bene ma sono assenti gli effetti grafici in alcune. Che sia un problema di CSS?

Ecco le foto così puoi farti un'idea.








Ultima modifica di lypo : 23-05-2011 alle 13:59.
lypo è offline   Rispondi citando il messaggio o parte di esso
Old 23-05-2011, 19:07   #6
Gimli[2BV!2B]
Senior Member
 
L'Avatar di Gimli[2BV!2B]
 
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
Prova ad utilizzare l'opzione --embedcss dello script, anche GMail scavalca i css non in linea come Lotus Notes.
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...)
Gimli[2BV!2B] è offline   Rispondi citando il messaggio o parte di esso
Old 24-05-2011, 17:11   #7
lypo
Member
 
L'Avatar di lypo
 
Iscritto dal: Jun 2010
Città: prov. Parma
Messaggi: 168
Avvevo provato anche con quello ma stesso risultato...
lypo è offline   Rispondi citando il messaggio o parte di esso
Old 24-05-2011, 22:31   #8
Gimli[2BV!2B]
Senior Member
 
L'Avatar di Gimli[2BV!2B]
 
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
Nel mio Nagios ho notato che l'indirizzo relativo dei css è leggermente diverso rispetto a quello presente nelle espressioni regolari dello script.

Prova a modificare le righe in grassetto:
Codice:
if ($webcssembed) {
	# Stupid hacks for dodgy notes
	$nagssbody		=	http_request("$webbase/stylesheets/summary.css");
	$nagsssummary = "<style type=\"text\/css\">\n";
	foreach ( split(/\n/,$nagssbody) ) {
		chomp;
		if (not defined $_ or $_ eq "" ) {
			next;
		}
		$nagsssummary .= "<!-- $_ -->\n";
	}
	$nagsssummary .= "</style>\n";
	$nagsssummary .= "<base href=\"$webbase/cgi-bin/\">\n";

	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'/stylesheets/common.css\'>@@;
	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'/stylesheets/summary.css\'>@$nagsssummary@;
}
In questo modo:
Codice:
if ($webcssembed) {
	# Stupid hacks for dodgy notes
	$nagssbody		=	http_request("$webbase/stylesheets/summary.css");
	$nagsssummary = "<style type=\"text\/css\">\n";
	foreach ( split(/\n/,$nagssbody) ) {
		chomp;
		if (not defined $_ or $_ eq "" ) {
			next;
		}
		$nagsssummary .= "<!-- $_ -->\n";
	}
	$nagsssummary .= "</style>\n";
	$nagsssummary .= "<base href=\"$webbase/cgi-bin/\">\n";

	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'/nagios/stylesheets/common.css\'>@@;
	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'/nagios/stylesheets/summary.css\'>@$nagsssummary@;
}
Se non dovesse funzionare controlla cosa c'è scritto nei LINK REL='stylesheet' della mail che ricevi e/o il contenuto del blocco <style type="text/css"></style>, ovvero gli stili embedded generati.
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...)

Ultima modifica di Gimli[2BV!2B] : 24-05-2011 alle 22:34.
Gimli[2BV!2B] è offline   Rispondi citando il messaggio o parte di esso
Old 25-05-2011, 17:37   #9
lypo
Member
 
L'Avatar di lypo
 
Iscritto dal: Jun 2010
Città: prov. Parma
Messaggi: 168
Non funziona lo stesso.

In una mail non c'è il LINK REL='stylesheet' ed il contenuto del blocco <style type="text/css"></style> è:

Codice:
<style type="text/css">
<!-- .summary { font-family: arial,serif;  background-color: white;  color: black;  font-size: 10pt; } -->
<!-- .errorMessage { font-family: arial,serif;  text-align: center;  color: red;  font-weight: bold;  font-size: 12pt; } -->
<!-- .errorDescription { font-family: arial,serif;  text-align: center;  font-weight: bold;  font-size: 12pt; } -->
<!-- .warningMessage { font-family: arial,serif;  text-align: center;  color: red;  font-weight: bold;  font-size: 10pt; } -->
<!-- .infoBox { font-family: arial,serif;  font-size: 8pt;  background-color: #C4C2C2;  padding: 2; } -->
<!-- .infoBoxTitle { font-family: arial,serif;  font-size: 10pt;  font-weight: bold; } -->
<!-- .infoBoxBadProcStatus { font-family: arial,serif;  color: red; } -->
<!-- A.homepageURL:Hover { font-family: arial,serif;  color: red; } -->
<!-- .linkBox { font-family: arial,serif;  font-size: 8pt;  background-color: #DBDBDB;  padding: 1; } -->
<!-- .reportRange { font-family: arial,serif;  text-align: center;  font-weight: bold;  font-size: 10pt; } -->
<!-- .reportDuration { font-family: arial,serif;  text-align: center;  font-size: 8pt; } -->
<!-- .reportTime { font-family: arial,serif;  text-align: center;  font-size: 8pt; } -->
<!-- .reportDataEven { font-family: arial,serif;  font-size: 8pt;  background-color: #B4B5CC;  padding: 2; } -->
<!-- .reportDataOdd { font-family: arial,serif;  font-size: 8pt;  background-color: #CDCEE9;  padding: 2; } -->
<!-- .dataTitle { font-family: arial,serif;  text-align: center;  font-weight: bold;  font-size: 12pt; } -->
<!-- .dataSubTitle { font-family: arial,serif;  text-align: center;  font-weight: bold;  font-size: 10pt; } -->
<!-- TABLE.data { font-family: arial,serif;  font-size: 10pt;  background-color: white;  padding: 2; } -->
<!-- TH.data { font-family: arial,serif;  font-size: 10pt;  background-color: white;  text-align: left;  background-color: #999797;  color: #DCE5C1; } -->
<!-- .dataOdd { font-family: arial,serif;  font-size: 9pt;  background-color: #DBDBDB; } -->
<!-- .dataEven { font-family: arial,serif;  font-size: 9pt;  background-color: #C4C2C2; } -->
<!-- .hostUP { font-family: arial,serif;  font-size: 9pt;  text-align: left;  background-color: #33FF00; } -->
<!-- .hostDOWN { font-family: arial,serif;  font-size: 9pt;  text-align: left;  background-color: #F83838; } -->
<!-- .hostUNREACHABLE { font-family: arial,serif;  font-size: 9pt;  text-align: left;  background-color: #F83838; } -->
<!-- .serviceOK { font-family: arial,serif;  font-size: 9pt;  text-align: left;  background-color: #33FF00; } -->
<!-- .serviceWARNING { font-family: arial,serif;  font-size: 9pt;  text-align: left;  background-color: #FFFF00; } -->
<!-- .serviceUNKNOWN { font-family: arial,serif;  font-size: 9pt;  text-align: left;  background-color: #FF9900; } -->
<!-- .serviceCRITICAL { font-family: arial,serif;  font-size: 9pt;  text-align: left;  background-color: #F83838; } -->
<!-- .optBox { font-family: arial narrow,serif;  font-size: 10pt;  font-weight: bold; } -->
<!-- .optBoxTitle { font-family: arial,serif;  font-weight: bold;  font-size: 10pt; } -->
<!-- .optBoxItem { font-family: arial,serif;  font-size: 8pt;  font-weight: bold; } -->
<!-- .optBoxValue { font-family: arial,serif;  font-size: 8pt;  font-style: italic; } -->
<!-- .helpfulHint { font-family: arial,serif;  text-align: left;  font-size: 8pt;  font-style: italic;  text-align: center; } -->
<!-- .dateSelectTitle { font-family: arial,serif;  text-align: center;  font-weight: bold;  font-size: 12pt; } -->
<!-- .dateSelectSubTitle { font-family: arial,serif;  text-align: left;  font-weight: bold;  font-size: 10pt; } -->
<!-- .dateSelectItem { font-family: arial,serif;  text-align: left;  font-size: 8pt; } -->
<!-- .reportSelectTip { font-family: arial,serif;  text-align: left;  font-size: 8pt;  font-style: italic; } -->
<!-- .reportSelectTitle { font-family: arial,serif;  text-align: center;  font-weight: bold;  font-size: 12pt; } -->
<!-- .reportSelectSubTitle { font-family: arial,serif;  text-align: right;  font-size: 10pt; } -->
<!-- .reportSelectItem { font-family: arial,serif;  text-align: left;  font-size: 8pt; } -->
</style>

Mentre in un'altra mail è presente soltanto il LINK REL='stylesheet'
Codice:
<LINK REL='stylesheet' TYPE='text/css' HREF='/nagios/stylesheets/status.css'>

Mentre nel cestino avevo ancora una mail con 2 LINK REL (precedente alla modifica)
Codice:
<LINK REL='stylesheet' TYPE='text/css' HREF='/nagios/stylesheets/common.css'>
<LINK REL='stylesheet' TYPE='text/css' HREF='/nagios/stylesheets/summary.css'>

Ultima modifica di lypo : 25-05-2011 alle 18:14.
lypo è offline   Rispondi citando il messaggio o parte di esso
Old 25-05-2011, 22:27   #10
Gimli[2BV!2B]
Senior Member
 
L'Avatar di Gimli[2BV!2B]
 
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
Il risultato desiderato è il primo, ma, a quanto pare, non è sufficiente.
Lo temevo, gli stili devono essere tutti in linea negli elementi a cui sono relativi per scavalcare quelli delle interfacce webmail più diffuse.

Ho aggiunto l'opzione --inlinecss che, usando il modulo Python pynliner: applica gli stili del CSS a tutti gli elementi inserendoli nell'attributo style (posizione con massima priorità).
Il fatto di aver dovuto utilizzare Python non mi esalta molto, ma quel modulo è quello che mi ha convinto maggiormente tre le opzioni che ho rintracciato in rete.

Se pynliner non risultasse disponibile nei repository è possibile installarlo con il comando easy_install pynliner (con diritti root, preferibilmente).
Codice:
#!/usr/local/bin/perl -w
#
# Nagios overnight/daily/weekly/monthly reporter
#
# Fetches Nagios report from web, processes HTML/CSS and emails to someone
# Written by Rob Moss, 2005-07-26, [email protected]
# Little extension by Gimli, 2011-05-25
#
# Use at your own risk, knoweledge of perl required.
#
# Version 1.3.1
# - Overnight, Daily, Weekly, Monthly reports
# Version 1.3.1B
# - New option --inlinecss
#

use strict;
use Getopt::Long;
use Net::SMTP;
use LWP::UserAgent;
use Date::Manip;


my $mailhost	=	'maiserver.domain.com';				#	Fill these in!
my $maildomain	=	'domain.com';						#	Fill these in!
my $mailfrom	=	'[email protected]';					#	Fill these in!
my $mailto		=	'[email protected]';					#	Fill these in!
my $timeout		=	30;
my $mailsubject	=	'';
my $mailbody	=	'';

my $logfile		=	'/usr/local/nagios/var/mail.log';	#	Where would you like your logfile to live?
my $debug		=	1;									#	Set the debug level to 1 or higher for information

my $type		=	'';
my $repdateprev;
my $reporturl;

my $nagssbody;
my $nagsssummary;

my $webuser		=	'nagios';							#	Set this to a read-only nagios user (not nagiosadmin!)
my $webpass		=	'password';							#	Set this to a read-only nagios user (not nagiosadmin!)
my $webbase		=	'http://nagios-server.blah/nagios';	#	Set this to the base of Nagios web page
my $webcssembed =	0;
my $webcssinline =	0;


GetOptions (
	"debug=s"	=>	\$debug,
	"help"		=>	\&help,
	"type=s"	=>	\$type,
	"email=s"	=>	\$mailto,
	"embedcss"	=>	\$webcssembed,
	"inlinecss"	=>	\$webcssinline,
);


if (not defined $type or $type eq "") {
	help();
	exit;
}
elsif ($type eq "overnight") {
	report_overnight();
}
elsif ($type eq "daily") {
	report_daily();
}
elsif ($type eq "weekly") {
	report_weekly();
}
elsif ($type eq "monthly") {
	report_monthly();
}
else {
	die("Unknown report type $type\n");
}


debug(1,"reporturl: [$reporturl]");

$mailbody = http_request($reporturl);
if( $mailbody eq 0 ) {
	exit 1;
}
# Remove HTML comments: avoid problems with Pynliner if $webcssinline == 1
$mailbody =~ s/<!--(.|\s)*?-->//g;
if ($webcssembed || $webcssinline) {
	# --inlinecss depends on --embedcss
	debug(1,"Embed CSS!");
	# Stupid hacks for dodgy notes
	$nagssbody		=	http_request("$webbase/stylesheets/summary.css");
	if( $nagssbody eq 0 ) {
		exit 1;
	}
	$nagsssummary	= "<style type=\"text\/css\">\n";
	foreach ( split(/\n/,$nagssbody) ) {
		chomp;
		if (not defined $_ or $_ eq "" ) {
			next;
		}
		$nagsssummary .= "<!-- ";
		$nagsssummary .= lc($_);
		$nagsssummary .= " -->\n";
	}
	$nagsssummary .= "</style>\n";
	$nagsssummary .= "<base href=\"$webbase/cgi-bin/\">\n";

	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'/nagios/stylesheets/common.css\'>@@;
	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'/nagios/stylesheets/summary.css\'>@$nagsssummary@;
}

my $output = "/tmp/nagios-report-htmlout.html";
open(FILE, "> $output") or warn "can't open file $output: $!\n";

if ($webcssinline) {
	debug(1,"Inline CSS!");
	close FILE;
	chomp(my $Python = `which python`);
	debug(1,"Inline CSS: python executable -> $Python");
	if ( $Python eq "" ) {
		debug(0,"Inline CSS: python executable not found!");
		exit 1;
	}
	else {
		# Escape some problematic characters
		$mailbody =~ s/\n//g;
		$mailbody =~ s/\r//g;
		$mailbody =~ s/'/\\'/g;
		$mailbody =~ s/"/\\"/g;
		my $Script = "import pynliner; output = pynliner.fromString('$mailbody'); print(output);";
		my $status = system "$Python -c \"$Script\" >$output";
		if( $status != 0 ) {
			debug(0,"Inline CSS: Python error.");
			debug(0,"            Is Python module \"Pynliner\" installed?");
			debug(0,"      http://pypi.python.org/pypi/pynliner");
		}
	}
}
else {
	print FILE $mailbody;
	close FILE;
}


sendmail();


###############################################################################
sub help {
print <<_END_;

Nagios web->email reporter program.

$0 <args>

--help
	This screen

--email=<email>
	Send to this address instead of the default address
	"$mailto"

--type=overnight	
	Overnight report, from 17h last working day to Today (9am)
--type=daily
	Daily report, 09:00 last working day to Today (9am)
--type=weekly
	Weekly report, 9am 7 days ago, until 9am today (run at 9am friday!)
--type=monthly
	Monthly report, 1st of prev month at 9am to last day of month, 9am

--embedcss
	Downloads the CSS file and embeds it into the main HTML to enable 
	Lotus Notes to work (yet another reason to hate Notes)

--inlinecss
	Downloads the CSS file and insert all the properties into inline
	styles of the relative elements. This force all the webmails to not
	override any CSS attribute.
	-> Selects --embedcss.
	-> Depends on Python and Python module Pynliner:
		http://pypi.python.org/pypi/pynliner

_END_

exit 1;

}

###############################################################################
sub report_monthly {
	# This should be run on the 1st of every month
	$repdateprev = DateCalc("yesterday",1);
	debug(1,"repdateprev = $repdateprev");
#				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = 01;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 0;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 0;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios alerts for month $repsmonth/$repsyear";

}

###############################################################################
sub report_weekly {
	# This should be run on Friday, 9am
	$repdateprev = Date_PrevWorkDay("today",5);
	debug(1,"repdateprev = $repdateprev");
				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = $3;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 9;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 9;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios alerts for week ending $repsday/$repsmonth/$repsyear";

}


###############################################################################
sub report_daily {
	$repdateprev = Date_PrevWorkDay("today",1);
	debug(1,"repdateprev = $repdateprev");
				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = $3;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 7;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 7;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios alerts for 24 hours $repsday/$repsmonth/$repsyear ${repshour}h to present";

}

###############################################################################
sub report_overnight {
	$repdateprev = Date_PrevWorkDay("today",1);
	debug(1,"repdateprev = $repdateprev");
				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = $3;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 17;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 9;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios overnight alerts from $repsday/$repsmonth/$repsyear ${repshour}h to present";

}

###############################################################################
sub http_request {
	my $ua;
	my $req;
	my $res;

	my $geturl = shift;
	if (not defined $geturl or $geturl eq "") {
		warn "No URL defined for http_request\n";
		return 0;
	}
	$ua = LWP::UserAgent->new;
	$ua->agent("Nagios Report Generator " . $ua->agent);
	$req = HTTP::Request->new(GET => $geturl);
	$req->authorization_basic($webuser, $webpass);
	$req->header(	'Accept'			=>	'text/html',
					'Content_Base'		=>	$webbase,
				);

	# send request
	$res = $ua->request($req);

	# check the outcome
	if ($res->is_success) {
		debug(1,"Retreived URL successfully");
		return $res->decoded_content;
	}
	else {
		print "Error: " . $res->status_line . "\n";
		return 0;
	}
}

###############################################################################
sub debug {
	my ($lvl,$msg) = @_;
	if ( defined $debug and $lvl <= $debug ) {
		chomp($msg);
		print localtime(time) .": $msg\n";
	}
	return 1;
}

#########################################################
sub sendmail {
	my $smtp = Net::SMTP->new(
			$mailhost,
			Hello => $maildomain,
			Timeout => $timeout,
			Debug   => $debug,
		);

	$smtp->mail($mailfrom);
	$smtp->to($mailto);

	$smtp->data();
	$smtp->datasend("To: $mailto\n");
	$smtp->datasend("From: $mailfrom\n");
	$smtp->datasend("Subject: $mailsubject\n");
	$smtp->datasend("MIME-Version: 1.0\n");
	$smtp->datasend("Content-type: multipart/mixed; boundary=\"boundary\"\n");
	$smtp->datasend("\n");
	$smtp->datasend("This is a multi-part message in MIME format.\n");
	$smtp->datasend("--boundary\n");
	$smtp->datasend("Content-type: text/html\n");
	$smtp->datasend("Content-Disposition: inline\n");
	$smtp->datasend("Content-Description: Nagios report\n");
	$smtp->datasend("$mailbody\n");
	$smtp->datasend("--boundary\n");
	$smtp->datasend("Content-type: text/plain\n");
	$smtp->datasend("Please read the attatchment\n");
	$smtp->datasend("--boundary--\n");


	$smtp->dataend();

	$smtp->quit;
}
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...)

Ultima modifica di Gimli[2BV!2B] : 25-05-2011 alle 23:09.
Gimli[2BV!2B] è offline   Rispondi citando il messaggio o parte di esso
Old 26-05-2011, 11:32   #11
lypo
Member
 
L'Avatar di lypo
 
Iscritto dal: Jun 2010
Città: prov. Parma
Messaggi: 168
Nel codice per generare la mail mi dice questo:

Codice:
Thu May 26 15:24:55 2011: Retreived URL successfully
Thu May 26 15:24:55 2011: Embed CSS!
Thu May 26 15:24:55 2011: Retreived URL successfully
Thu May 26 15:24:55 2011: Inline CSS!
Thu May 26 15:24:55 2011: Inline CSS: python executable -> /usr/bin/python
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/pynliner/__init__.py", line 187, in fromString
    return Pynliner().from_string(string).run()
  File "/usr/lib/python2.4/site-packages/pynliner/__init__.py", line 85, in run
    self._get_styles()
  File "/usr/lib/python2.4/site-packages/pynliner/__init__.py", line 105, in _get_styles
    self._get_external_styles()
  File "/usr/lib/python2.4/site-packages/pynliner/__init__.py", line 123, in _get_external_styles
    url = self.root_url + url
AttributeError: 'Pynliner' object has no attribute 'root_url'
Thu May 26 15:24:55 2011: Inline CSS: Python error.
Thu May 26 15:24:55 2011:             Is Python module "Pynliner" installed?
Thu May 26 15:24:55 2011:       http://pypi.python.org/pypi/pynliner
Net::SMTP>>> Net::SMTP(2.29)
Net::SMTP>>>   Net::Cmd(2.26)
Net::SMTP>>>     Exporter(5.58)
Net::SMTP>>>   IO::Socket::INET(1.29)
Net::SMTP>>>     IO::Socket(1.29)
Net::SMTP>>>       IO::Handle(1.25)

Spero che non sia dovuto al fatto che ho la versione 2.4

Inoltre da yum non mi vede la 2.6

Ultima modifica di lypo : 26-05-2011 alle 15:04.
lypo è offline   Rispondi citando il messaggio o parte di esso
Old 26-05-2011, 20:29   #12
Gimli[2BV!2B]
Senior Member
 
L'Avatar di Gimli[2BV!2B]
 
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
Ho visto quell'errore se nel file HTML erano presenti LINK REL='stylesheet'.
In quel caso il modulo cerca di scaricarli, ma non sa dove andare a trovarli, visto che gli passo una stringa: root_url è nullo.
Visto che l'errore lo riconosco escluderei un problema di versione.

Ho reso più aggressiva la rimozione dei LINK REL:
Codice:
#!/usr/local/bin/perl -w
#
# Nagios overnight/daily/weekly/monthly reporter
#
# Fetches Nagios report from web, processes HTML/CSS and emails to someone
# Written by Rob Moss, 2005-07-26, [email protected]
# Little extension by Gimli, 2011-05-26
#
# Use at your own risk, knoweledge of perl required.
#
# Version 1.3.1
# - Overnight, Daily, Weekly, Monthly reports
# Version 1.3.1B
# - New option --inlinecss
# Version 1.3.1C
# - Modified regular expressions for --embedcss
#

use strict;
use Getopt::Long;
use Net::SMTP;
use LWP::UserAgent;
use Date::Manip;


my $mailhost	=	'maiserver.domain.com';				#	Fill these in!
my $maildomain	=	'domain.com';						#	Fill these in!
my $mailfrom	=	'[email protected]';					#	Fill these in!
my $mailto		=	'[email protected]';					#	Fill these in!
my $timeout		=	30;
my $mailsubject	=	'';
my $mailbody	=	'';

my $logfile		=	'/usr/local/nagios/var/mail.log';	#	Where would you like your logfile to live?
my $debug		=	1;									#	Set the debug level to 1 or higher for information

my $type		=	'';
my $repdateprev;
my $reporturl;

my $nagssbody;
my $nagsssummary;

my $webuser		=	'nagios';							#	Set this to a read-only nagios user (not nagiosadmin!)
my $webpass		=	'password';							#	Set this to a read-only nagios user (not nagiosadmin!)
my $webbase		=	'http://nagios-server.blah/nagios';	#	Set this to the base of Nagios web page
my $webcssembed =	0;
my $webcssinline =	0;


GetOptions (
	"debug=s"	=>	\$debug,
	"help"		=>	\&help,
	"type=s"	=>	\$type,
	"email=s"	=>	\$mailto,
	"embedcss"	=>	\$webcssembed,
	"inlinecss"	=>	\$webcssinline,
);


if (not defined $type or $type eq "") {
	help();
	exit;
}
elsif ($type eq "overnight") {
	report_overnight();
}
elsif ($type eq "daily") {
	report_daily();
}
elsif ($type eq "weekly") {
	report_weekly();
}
elsif ($type eq "monthly") {
	report_monthly();
}
else {
	die("Unknown report type $type\n");
}


debug(1,"reporturl: [$reporturl]");

$mailbody = http_request($reporturl);
if( $mailbody eq 0 ) {
	exit 1;
}
# Remove HTML comments: avoid problems with Pynliner if $webcssinline == 1
$mailbody =~ s/<!--(.|\s)*?-->//g;
if ($webcssembed || $webcssinline) {
	# --inlinecss depends on --embedcss
	debug(1,"Embed CSS!");
	# Stupid hacks for dodgy notes
	$nagssbody		=	http_request("$webbase/stylesheets/summary.css");
	if( $nagssbody eq 0 ) {
		exit 1;
	}
	$nagsssummary	= "<style type=\"text\/css\">\n";
	foreach ( split(/\n/,$nagssbody) ) {
		chomp;
		if (not defined $_ or $_ eq "" ) {
			next;
		}
		$nagsssummary .= "<!-- ";
		$nagsssummary .= lc($_);
		$nagsssummary .= " -->\n";
	}
	$nagsssummary .= "</style>\n";
	$nagsssummary .= "<base href=\"$webbase/cgi-bin/\">\n";

	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'/(?:nagios/)stylesheets/summary.css\'>@$nagsssummary@;
	$mailbody =~ s@<LINK REL=\'stylesheet\' TYPE=\'text/css\'(.|\s)*.css\'>@@g;
}

my $output = "/tmp/nagios-report-htmlout.html";
open(FILE, "> $output") or warn "can't open file $output: $!\n";

if ($webcssinline) {
	debug(1,"Inline CSS!");
	close FILE;
	chomp(my $Python = `which python`);
	debug(1,"Inline CSS: python executable -> $Python");
	if ( $Python eq "" ) {
		debug(0,"Inline CSS: python executable not found!");
		exit 1;
	}
	else {
		# Escape some problematic characters
		$mailbody =~ s/\n//g;
		$mailbody =~ s/\r//g;
		$mailbody =~ s/'/\\'/g;
		$mailbody =~ s/"/\\"/g;
		my $Script = "import pynliner; output = pynliner.fromString('$mailbody'); print(output);";
		my $status = system "$Python -c \"$Script\" >$output";
		if( $status != 0 ) {
			debug(0,"Inline CSS: Python error.");
			debug(0,"            Is Python module \"Pynliner\" installed?");
			debug(0,"      http://pypi.python.org/pypi/pynliner");
		}
	}
}


sendmail();


###############################################################################
sub help {
print <<_END_;

Nagios web->email reporter program.

$0 <args>

--help
	This screen

--email=<email>
	Send to this address instead of the default address
	"$mailto"

--type=overnight	
	Overnight report, from 17h last working day to Today (9am)
--type=daily
	Daily report, 09:00 last working day to Today (9am)
--type=weekly
	Weekly report, 9am 7 days ago, until 9am today (run at 9am friday!)
--type=monthly
	Monthly report, 1st of prev month at 9am to last day of month, 9am

--embedcss
	Downloads the CSS file and embeds it into the main HTML to enable 
	Lotus Notes to work (yet another reason to hate Notes)

--inlinecss
	Downloads the CSS file and insert all the properties into inline
	styles of the relative elements. This force all the webmails to not
	override any CSS attribute.
	-> Selects --embedcss.
	-> Depends on Python and Python module Pynliner:
		http://pypi.python.org/pypi/pynliner

_END_

exit 1;

}

###############################################################################
sub report_monthly {
	# This should be run on the 1st of every month
	$repdateprev = DateCalc("yesterday",1);
	debug(1,"repdateprev = $repdateprev");
#				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = 01;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 0;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 0;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios alerts for month $repsmonth/$repsyear";

}

###############################################################################
sub report_weekly {
	# This should be run on Friday, 9am
	$repdateprev = Date_PrevWorkDay("today",5);
	debug(1,"repdateprev = $repdateprev");
				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = $3;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 9;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 9;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios alerts for week ending $repsday/$repsmonth/$repsyear";

}


###############################################################################
sub report_daily {
	$repdateprev = Date_PrevWorkDay("today",1);
	debug(1,"repdateprev = $repdateprev");
				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = $3;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 7;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 7;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios alerts for 24 hours $repsday/$repsmonth/$repsyear ${repshour}h to present";

}

###############################################################################
sub report_overnight {
	$repdateprev = Date_PrevWorkDay("today",1);
	debug(1,"repdateprev = $repdateprev");
				#2006072116:48:37
	my ($repsday, $repsmonth, $repsyear, $repshour ) = 0;
	$repdateprev =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repsday = $3;
	$repsmonth = $2;
	$repsyear = $1;
	$repshour = 17;

	my ($repeday, $repemonth, $repeyear, $repehour ) = 0;
	my $repdatenow = ParseDate("today");
	debug(1,"repdatenow = $repdatenow");
	$repdatenow =~ /(\d\d\d\d)(\d\d)(\d\d)(.*)/;
	$repeday = $3;
	$repemonth = $2;
	$repeyear = $1;
	$repehour = 9;

	$reporturl	=	"$webbase/cgi-bin/summary.cgi?report=1&displaytype=1&timeperiod=custom" .
						"&smon=$repsmonth&sday=$repsday&syear=$repsyear&shour=$repshour&smin=0&ssec=0" .
						"&emon=$repemonth&eday=$repeday&eyear=$repeyear&ehour=$repehour&emin=0&esec=0" .
						'&hostgroup=all&servicegroup=all&host=all&alerttypes=3&statetypes=2&hoststates=3&servicestates=56&limit=500';
	$mailsubject = "Nagios overnight alerts from $repsday/$repsmonth/$repsyear ${repshour}h to present";

}

###############################################################################
sub http_request {
	my $ua;
	my $req;
	my $res;

	my $geturl = shift;
	if (not defined $geturl or $geturl eq "") {
		warn "No URL defined for http_request\n";
		return 0;
	}
	$ua = LWP::UserAgent->new;
	$ua->agent("Nagios Report Generator " . $ua->agent);
	$req = HTTP::Request->new(GET => $geturl);
	$req->authorization_basic($webuser, $webpass);
	$req->header(	'Accept'			=>	'text/html',
					'Content_Base'		=>	$webbase,
				);

	# send request
	$res = $ua->request($req);

	# check the outcome
	if ($res->is_success) {
		debug(1,"Retrieved URL successfully");
		return $res->decoded_content;
	}
	else {
		print "Error: " . $res->status_line . "\n";
		return 0;
	}
}

###############################################################################
sub debug {
	my ($lvl,$msg) = @_;
	if ( defined $debug and $lvl <= $debug ) {
		chomp($msg);
		print localtime(time) .": $msg\n";
	}
	return 1;
}

#########################################################
sub sendmail {
	my $smtp = Net::SMTP->new(
			$mailhost,
			Hello => $maildomain,
			Timeout => $timeout,
			Debug   => $debug,
		);

	$smtp->mail($mailfrom);
	$smtp->to($mailto);

	$smtp->data();
	$smtp->datasend("To: $mailto\n");
	$smtp->datasend("From: $mailfrom\n");
	$smtp->datasend("Subject: $mailsubject\n");
	$smtp->datasend("MIME-Version: 1.0\n");
	$smtp->datasend("Content-type: multipart/mixed; boundary=\"boundary\"\n");
	$smtp->datasend("\n");
	$smtp->datasend("This is a multi-part message in MIME format.\n");
	$smtp->datasend("--boundary\n");
	$smtp->datasend("Content-type: text/html\n");
	$smtp->datasend("Content-Disposition: inline\n");
	$smtp->datasend("Content-Description: Nagios report\n");
	$smtp->datasend("$mailbody\n");
	$smtp->datasend("--boundary\n");
	$smtp->datasend("Content-type: text/plain\n");
	$smtp->datasend("Please read the attatchment\n");
	$smtp->datasend("--boundary--\n");


	$smtp->dataend();

	$smtp->quit;
}
Se l'errore dovesse rimanere, prova ad eseguirlo con solo --embedcss e riporta quali stili sono presenti tra LINK REL='stylesheet' e <style type="text/css"></style> (basta qualche riga).
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...)
Gimli[2BV!2B] è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Kindle Scribe Colorsoft: riduce le cornici e diventa a colori, ma il prezzo è alto Kindle Scribe Colorsoft: riduce le cornici e div...
L'IA cambia tutte le regole della sicurezza tra vulnerabilità e sorveglianza. Intervista al CEO di Proofpoint L'IA cambia tutte le regole della sicurezza tra ...
L'Europa conta nella tecnologia e può essere autonoma. Cosa si è detto al Nextcloud Summit 2026 L'Europa conta nella tecnologia e può ess...
Dreame X60 Pro Ultra Complete: i bracci si estendono sempre di più Dreame X60 Pro Ultra Complete: i bracci si esten...
TCL 65C8L, la recensione del SQD-Mini LED da 4400 nit misurati TCL 65C8L, la recensione del SQD-Mini LED da 440...
Rocket Lab acquisisce Iridium: nasce un ...
Una ventola nascosta e un design fuori d...
Display e fotocamera insieme: a Zurigo n...
Lenovo Idea Tab Plus, il tablet per stud...
Un ingegnere di AMD ha riprodotto in cas...
SanDisk Optimus cresce con nuovi SSD cer...
Loongson contro Intel e AMD: dalla Cina ...
Australia, quasi tutti gli under-16 aggi...
Oltre 1.300 miliardi di dollari per la p...
Un nuovo studio mette in dubbio la natur...
Crisi Volkswagen, torna l'ipotesi cessio...
Il CERN spegne il Large Hadron Collider:...
Stranger Than Heaven avrà una storia mol...
Il futuro prezzo di PS6 preoccupa i gioc...
AMD Ryzen 10000 sempre più vicini...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 21:28.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v