This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<html>
<head>
</head>
<body>
<a href="runon.pl">Wochentage an denen Checks laufen sollen</a><br>
<a href="notrunon.pl">Feiertage an denen Checks nicht laufen sollen</a><br>
<a href="del_alerts_log.pl">Alerts-Log Tabelle leeren</a><br>
</body>
</html>

View File

@@ -0,0 +1,24 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<meta http-equiv='refresh' content='10; alerts_log.pl'>\n";
print "</head>\n";
print "<body>\n";
my $sth = $dbh->prepare("select date,time,msg,host_hostname,service_result from alerts_log order by date desc, time desc");
$sth->execute;
print "<table border='1'>\n";
print "<tr><td>Datum</td><td>Zeit</td><td>Nachricht</td><td>Hostname</td><td>Dienstergebnis</td></tr>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr><td>$ref->[0]</td><td>$ref->[1]</td><td>$ref->[2]</td><td>$ref->[3]</td><td>$ref->[4]</td></tr>\n";
}
print "</table>\n";
print "</body>\n";
print "</html>\n";

675
Perl CGI C2/admin/c2.pl Normal file
View File

@@ -0,0 +1,675 @@
#!/bin/perl
use Mysql;
use strict;
use Net::SNMP;
use Net::Ping;
use BER;
require 'SNMP_Session.pm';
use Data::Dumper;
our ($c2,$dbh);
main();
sub main {
$dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
while (1) {
read_database();
$c2->{'time'} = get_time();
$c2->{'date'} = get_date();
print "$c2->{'date'} $c2->{'time'}\n";
if(run_now()) {
foreach my $todo (keys %{$c2->{'todo'}}) {
get_service_value($todo);
}
#open TEST, ">TEST.txt";
#print TEST Dumper ($c2);
#close TEST;
create_web_from_template();
}
print "\n";
sleep ($c2->{'conf'}->{'check_intervall'});
}
}
sub run_now {
my $should_run=1;
my %ts;
($ts{"ss"},$ts{"mm"},$ts{"hh"},$ts{"dd"},$ts{"mon"},$ts{"yy"},$ts{"we"},$ts{"doy"},$ts{"st"})=localtime;
$ts{'yy'}+=1900; $ts{'mon'}++;
#print "$ts{'yy'} $ts{'mon'} $ts{'dd'} $ts{'we'}\n";
my $sth = $dbh->prepare("select value from run_on where day='$ts{'we'}'");
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
if ($ref->[0] == 0) {
$should_run=0;
}
}
#my $datum = "$ts{'yy'}"."-"."$ts{'mon'}"."-"."$ts{'dd'}";
my $datum = "$ts{'yy'}"."-";
if ($ts{'mon'} <10 ) {
$datum=$datum ."0$ts{'mon'}"."-";
}
else {
$datum=$datum . "$ts{'mon'}"."-";
}
if ($ts{'dd'} <10 ) {
$datum=$datum . "0$ts{'dd'}";
}
else {
$datum=$datum . "$ts{'dd'}";
}
#print "## $datum\n";
my $sel="select description from not_run_on where datum='$datum'";
#print "### $sel\n";
my $sth = $dbh->prepare($sel);
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
#print "#### $ref->[0]\n";
if ($ref->[0] ne "") {
$should_run=0;
}
}
my $sel="select start_time from conf where active = '1'";
my $sth = $dbh->prepare($sel);
my $start_time;
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
$start_time=$ref->[0];
}
my ($stah,$stam,$stas);
($stah,$stam,$stas) = split /:/,$start_time;
my $start_timestamp=$stah*3600 + $stam*60 + $stas;
my $sel="select stop_time from conf where active = '1'";
my $sth = $dbh->prepare($sel);
my $stop_time;
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
$stop_time=$ref->[0];
}
my ($stoh,$stom,$stos);
($stoh,$stom,$stos) = split /:/,$stop_time;
my $stop_timestamp=$stoh*3600 + $stom*60 + $stos;
my $akt_timestamp = $ts{'hh'}*3600 + $ts{'mm'}*60 + $ts{'ss'};
if ( ($akt_timestamp < $start_timestamp) or ($akt_timestamp > $stop_timestamp) ) {
$should_run = 0;
}
return $should_run;
}
sub clear_values {
foreach my $td (keys %{$c2->{'todo'}}) {
foreach my $posi (keys %{$c2->{'todo'}->{$td}->{'services'}}) {
$c2->{'todo'}->{$td}->{'services'}->{$posi}->{'ergebnis'}="";
$c2->{'todo'}->{$td}->{'services'}->{$posi}->{'error'}=0;
}
}
}
sub create_web_from_template {
my ($zeile_orig,$zeile,$host,$td,$count);
open IN, "<$c2->{'conf'}->{'web_template'}";
open OUT, ">index.html";
if ($c2->{'conf'}->{'web_enable'}==1) {
$count=0;
while (<IN>) {
my $metarefresh = "<meta http-equiv='refresh' content='$c2->{'conf'}->{'web_refresh_intervall'}; $c2->{'conf'}->{'web_link'}'>";
if (/\[C2REPEAT\]/) {
s/\[C2REPEAT\]//;
my $when=0; # 0:immer 1:Nur bei Fehler 2:Nur wenn kein Fehler
if (/DisplayError/) { $when = 1; }
elsif (/DisplayGood/) { $when = 2; }
elsif (/DisplayAll/) { $when = 0; }
s/DisplayError//;
s/DisplayGood//;
s/DisplayAll//;
$zeile_orig=$_;
foreach $td (sort keys %{$c2->{'todo'}}) {
if (display("$td","$when")) {
$zeile = $zeile_orig;
#$host = $c2->{'todo'}->{$td}->{'hosts'}->{'hostname'};
if ($count==1) {
$zeile =~ s/<tr>/<tr bgcolor='a0ffa0'>/;
$count = 0;
}
else {
$zeile =~ s/<tr>/<tr bgcolor='ffffa0'>/;
$count = 1;
}
$zeile =~ s/\[C2HOSTNAME\]/$c2->{'todo'}->{$td}->{'hosts'}->{'hostname'}/;
#<a href='admin\/edit_host\.pl\?edit=$c2->{'todo'}->{$td}->{'hosts'}->{'ind'}&edit1=Edit' target='new'>$c2->{'todo'}->{$td}->{'hosts'}->{'hostname'}<\/a>/;
$zeile =~ s/\[C2HOSTIP\]/$c2->{'todo'}->{$td}->{'hosts'}->{'ip'}/;
$zeile =~ s/\[C2HOSTDESCRIPTION\]/<a href='$c2->{'conf'}->{'config_url'}edit_host\.pl\?edit=$c2->{'todo'}->{$td}->{'hosts'}->{'ind'}&edit1=Edit' target='konfig'>$c2->{'todo'}->{$td}->{'hosts'}->{'description'}<\/a>/;
$zeile =~ s/\[C2CHECKIF\]/$c2->{'todo'}->{$td}->{'checks'}->{'beding'}/;
$zeile =~ s/\[C2CHECKVALUE\]/$c2->{'todo'}->{$td}->{'checks'}->{'wert'}/;
$zeile =~ s/\[C2CHECKDESCRIPTION\]/<a href='$c2->{'conf'}->{'config_url'}edit_check\.pl?edit=$c2->{'todo'}->{$td}->{'checks'}->{'ind'}&edit1=Edit' target='konfig'>$c2->{'todo'}->{$td}->{'checks'}->{'description'}<\/a>/;
$zeile =~ s/\[C2ALERTTYPE\]/$c2->{'todo'}->{$td}->{'alerts'}->{'alert_type'}/;
$zeile =~ s/\[C2ALERTDESCRIPTION\]/<a href='$c2->{'conf'}->{'config_url'}edit_alert\.pl?edit=$c2->{'todo'}->{$td}->{'alerts'}->{'ind'}&edit1=Edit' target='konfig'>$c2->{'todo'}->{$td}->{'alerts'}->{'description'}<\/a>/;
foreach my $sid (keys %{$c2->{'todo'}->{$td}->{'services'}}) {
if ($c2->{'todo'}->{$td}->{'services'}->{$sid}->{'todo'} eq "R") {
if ($c2->{'todo'}->{$td}->{'services'}->{$sid}->{'error'}=='1') {
$zeile =~ s/\[C2ERROR\]/<font color='FF0000'><b>$c2->{'todo'}->{$td}->{'services'}->{$sid}->{'error'}<\/b><\/font>/;
}
else {
$zeile =~ s/\[C2ERROR\]/<font color='00FF00'><b>$c2->{'todo'}->{$td}->{'services'}->{$sid}->{'error'}<\/b><\/font>/;
}
}
}
foreach my $sid (keys %{$c2->{'todo'}->{$td}->{'services'}}) {
if ($c2->{'todo'}->{$td}->{'services'}->{$sid}->{'todo'} eq "R") {
$zeile =~ s/\[C2SERVICENAME\]/$c2->{'todo'}->{$td}->{'services'}->{$sid}->{'description'}/;
}
}
foreach my $sid (keys %{$c2->{'todo'}->{$td}->{'services'}}) {
if ($c2->{'todo'}->{$td}->{'services'}->{$sid}->{'todo'} eq "R") {
my $erg = $c2->{'todo'}->{$td}->{'services'}->{$sid}->{'ergebnis'};
unless ($erg =~ /[a-zA-Z]/) {
$erg =~ s/\./,/;
$erg =~ s/(.*,[0-9]{0,2})[0-9]*/$1/;
}
$zeile =~ s/\[C2RESULT\]/$erg/;
}
}
foreach my $sid (keys %{$c2->{'todo'}->{$td}->{'services'}}) {
if ($c2->{'todo'}->{$td}->{'services'}->{$sid}->{'todo'} eq "R") {
$zeile =~ s/\[C2SERVICETIME\]/$c2->{'todo'}->{$td}->{'services'}->{$sid}->{'check_time'}/;
}
}
print OUT "$zeile";
}
}
}
else {
s/\[C2METAREFRESH\]/$metarefresh/;
s/\[C2CONFIGURL\]/$c2->{'conf'}->{'config_url'}/;
print OUT "$_";
}
}
}
else {
print OUT "<html>\n<head>\n";
print OUT "<meta http-equiv='refresh' content='$c2->{'conf'}->{'web_refresh_intervall'}; $c2->{'conf'}->{'web_link'}'>\n";
print OUT "</head>\n<body>\n";
print OUT "Webanzeige ist ausgeschaltet!<br><br>\n";
print OUT "<a href='$c2->{'conf'}->{'config_url'}' target='konfig'>Konfiguration & Administration</a>\n";
print OUT "</body>\n</html>";
}
close IN;
close OUT;
}
sub display {
my ($todo,$when) = @_;
# $when 0:immer 1:Nur bei Fehler 2:Nur wenn kein Fehler soll angezeigt werden!
my $ret;
foreach my $sid (keys %{$c2->{'todo'}->{$todo}->{'services'}}) {
if ($c2->{'todo'}->{$todo}->{'services'}->{$sid}->{'todo'} eq "R") {
if ($c2->{'todo'}->{$todo}->{'services'}->{$sid}->{'error'}=='1') {
$ret = 1 if ($when == 0 or $when == 1);
$ret = 0 if ($when == 2);
}
if ($c2->{'todo'}->{$todo}->{'services'}->{$sid}->{'error'}=='0') {
$ret = 1 if ($when == 0 or $when == 2);
$ret = 0 if ($when == 1);
}
}
}
return $ret;
}
sub get_service_value {
my ($todo)=@_;
my ($va1,$va2,$service_error);
foreach my $position (sort keys %{$c2->{'todo'}->{$todo}->{'services'}}) {
$service_error = 0;
if ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'todo'} eq "S") {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = get_snmp_value($todo,$position);
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'todo'} eq "P") {
if ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'} eq "IP") {
if (ping ($c2->{'todo'}->{$todo}->{'hosts'}->{'ip'})) {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = 1;
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'error'} = 0;
}
else {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'error'}->{2}->{'error_text'};;
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'error'} = 1;
}
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'} eq "HOST") {
if (ping ($c2->{'todo'}->{$todo}->{'hosts'}->{'hostname'})) {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = 1;
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'error'} = 0;
}
else {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'error'}->{2}->{'error_text'};;
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'error'} = 1;
}
}
else {
alert_log($todo,$position,"Ungültiger Adresstyp. Nur IP,HOST erlaubt.");
}
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'todo'} eq "K") {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'};
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'todo'} eq "C") {
my $var = $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'};
if ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'} =~ /\//) {
($va1,$va2) = split /\//,$var;
$va1 = delete_front_back_spaces($va1);
$va2 = delete_front_back_spaces($va2);
if ($c2->{'todo'}->{$todo}->{'services'}->{"$va2"}->{'ergebnis'} == 0) {
alert_log($todo,$position,"Division by 0.");
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'error'} = 1;
}
else {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'todo'}->{$todo}->{'services'}->{"$va1"}->{'ergebnis'} / $c2->{'todo'}->{$todo}->{'services'}->{"$va2"}->{'ergebnis'};
}
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'} =~ /\*/) {
($va1,$va2) = split /\*/,$var;
$va1 = delete_front_back_spaces($va1);
$va2 = delete_front_back_spaces($va2);
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'todo'}->{$todo}->{'services'}->{"$va1"}->{'ergebnis'} * $c2->{'todo'}->{$todo}->{'services'}->{"$va2"}->{'ergebnis'};
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'} =~ /\+/) {
($va1,$va2) = split /\+/,$var;
$va1 = delete_front_back_spaces($va1);
$va2 = delete_front_back_spaces($va2);
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'todo'}->{$todo}->{'services'}->{"$va1"}->{'ergebnis'} + $c2->{'todo'}->{$todo}->{'services'}->{"$va2"}->{'ergebnis'};
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'} =~ /\-/) {
($va1,$va2) = split /\-/,$var;
$va1 = delete_front_back_spaces($va1);
$va2 = delete_front_back_spaces($va2);
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'todo'}->{$todo}->{'services'}->{"$va1"}->{'ergebnis'} - $c2->{'todo'}->{$todo}->{'services'}->{"$va2"}->{'ergebnis'};
}
else {
alert_log($todo,$position,"Ungültige Rechenart. Nur +-*/ erlaubt.");
}
}
elsif ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'todo'} eq "R") {
my $var = $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'variable'};
($va1,$va2) = split /\-/,$var;
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'old_time'} = $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'new_time'};
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'new_time'} = get_timestamp();
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'check_time'} = get_time();
$va1 = delete_front_back_spaces($va1);
$va2 = delete_front_back_spaces($va2);
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'old_value'} = $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'new_value'};
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'new_value'} = $c2->{'todo'}->{$todo}->{'services'}->{"$va2"}->{'ergebnis'};
if ($va1 eq "A") {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'new_value'};
}
elsif ($va1 eq "R") {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'ergebnis'} = ($c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'new_value'} - $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'old_value'})/( $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'new_time'} - $c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'old_time'} );
}
else {
alert_log($todo,$position,"Ungültige Art bei Ergebnis. Nur A und R erlaubt.");
}
if (check_if_error($todo,$position)) { ####
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'error'} = 1;
send_alert ($todo,$position);
alert_log ($todo,$position,"Beding. erfüllt! => Alarm wurde gesendet");
}
else {
$c2->{'todo'}->{$todo}->{'services'}->{"$position"}->{'error'} = 0;
}
}
else {
alert_log($todo,$position,"Ungültiger Check. Nur K,C,S,P,R erlaubt.");
}
}
}
sub send_alert {
my ($todo,$position) = @_;
if ($c2->{'todo'}->{$todo}->{'alerts'}->{'alert_type'} eq "snmp") {
send_trap($todo);
}
elsif ($c2->{'todo'}->{$todo}->{'alerts'}->{'alert_type'} eq "mail") {
;
}
else {
alert_log($todo,$position,"Ungültiger Alarmtyp. Nur snmp und mail erlaubt.");
}
}
sub send_trap {
my ($todo) = @_;
my $dest_host = $c2->{'todo'}->{$todo}->{'alerts'}->{'destination'};
my $src_host = $c2->{'todo'}->{$todo}->{'hosts'}->{'ip'};
my $generic = $c2->{'todo'}->{$todo}->{'alerts'}->{'generic'};
my $specific = $c2->{'todo'}->{$todo}->{'alerts'}->{'specific'};
my $txt = $c2->{'todo'}->{$todo}->{'alerts'}->{'txt_msg'};
my $community = $c2->{'todo'}->{$todo}->{'alerts'}->{'community'};
my $port = $c2->{'todo'}->{$todo}->{'alerts'}->{'port'};
my $enterprise = $c2->{'todo'}->{$todo}->{'alerts'}->{'enterprise'};
my @t = split /\./,$enterprise; # Traps(Parameter 'TRAP')
my $trap_session = SNMP_Session->open ($dest_host, $community, $port); # Destination-IP(Parameter 'D'); Community(Parameter 'C')
$trap_session->trap_request_send(encode_oid(@t),
encode_ip_address($src_host), #$s_ip # Source-IP(Parameter 'S')
encode_int($generic), # Priorität(Parameter 'P') 0:coldStart 1:warmstart 2:linkdown 3:linkup 4:authenticationfailure 5:egpneighborloss 6:enterprise
encode_int($specific), # wenn hier 0 ist.
encode_string($txt));
}
sub error_log {
my ($todo,$position,$msg) = @_;
open FILE, ">>$c2->{'conf'}->{'errors_log'}";
print FILE "$c2->{'date'} $c2->{'time'} $msg Tabelle services ind# $c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ind'}\n";
close FILE;
}
sub alert_log {
my ($todo,$position,$msg) = @_;
my $v1=$c2->{'date'};
my $v2=$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'check_time'};
my $v3=$c2->{'todo'}->{$todo}->{'hosts'}->{'description'};
my $v4=$c2->{'todo'}->{$todo}->{'hosts'}->{'hostname'};
my $v5=$c2->{'todo'}->{$todo}->{'hosts'}->{'ip'};
my $v6=$c2->{'todo'}->{$todo}->{'checks'}->{'description'};
my $v7=$c2->{'todo'}->{$todo}->{'checks'}->{'beding'};
my $v8=$c2->{'todo'}->{$todo}->{'checks'}->{'wert'};
my $v9=$c2->{'todo'}->{$todo}->{'alerts'}->{'description'};
my $va=$c2->{'todo'}->{$todo}->{'alerts'}->{'alert_type'};
my $vb=$c2->{'todo'}->{$todo}->{'hosts'}->{'ind'};
my $vc=$c2->{'todo'}->{$todo}->{'checks'}->{'ind'};
my $vd=$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ind'};
my $ve=$c2->{'todo'}->{$todo}->{'alerts'}->{'ind'};
my $vf=$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'service_ind'};
my $vg=$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ergebnis'};
$dbh->do("insert into alerts_log (date,time,host_description,host_hostname,host_ip,check_description,check_beding,check_wert,alert_description,alert_alert_type,host_ind,alert_ind,check_ind,pos_in_service,service_nr,msg,service_result) values ('$v1','$v2','$v3','$v4','$v5','$v6','$v7','$v8','$v9','$va','$vb','$ve','$vc','$position','$vf','$msg','$vg')");
}
sub check_if_error {
my ($todo,$position) = @_;
my $error=0;
my $more_checks = 1;
my $ergebnis = $c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ergebnis'};
my $bed = $c2->{'todo'}->{$todo}->{'checks'}->{'beding'};
my $value = $c2->{'todo'}->{$todo}->{'checks'}->{'wert'};
# alle todo-$todo-services-$posi durchlaufen
# alle error durchlaufen
# wenn todo-$todo-services-$posi-ergebnis eq error-$error-error_text
# alle todo-$todo-services-$posi durchlaufen
# wenn todo-$todo-services-$posi-todo eq R
# todo-$todo-services-$posi-ergebnis = error-$error-error_text
# $error=1
# $no_more_checks=0
foreach my $posi1 ( keys %{$c2->{'todo'}->{$todo}->{'services'}} ) {
foreach my $err1 ( keys %{$c2->{'error'}} ) {
if ($c2->{'todo'}->{$todo}->{'services'}->{$posi1}->{'ergebnis'} eq $c2->{'error'}->{$err1}->{'error_text'} ) {
foreach my $posi2 ( keys %{$c2->{'todo'}->{$todo}->{'services'}} ) {
if ($c2->{'todo'}->{$todo}->{'services'}->{$posi2}->{'todo'} eq "R") {
$c2->{'todo'}->{$todo}->{'services'}->{$posi2}->{'ergebnis'} = $c2->{'error'}->{$err1}->{'error_text'};
$error = 1;
$more_checks=0;
}
}
}
}
}
if ($more_checks) {
if ($bed eq "LT") { if ($ergebnis < $value) {$error=1;} }
elsif ($bed eq "NLT") { unless ($ergebnis < $value) {$error=1;} }
elsif ($bed eq "GT") { if ($ergebnis > $value) {$error=1;} }
elsif ($bed eq "NGT") { unless ($ergebnis < $value) {$error=1;} }
elsif ($bed eq "EQ") { if ($ergebnis eq $value) {$error=1;} }
elsif ($bed eq "NEQ") { if ($ergebnis ne $value) {$error=1;} }
elsif ($bed eq "RE") { if ($ergebnis =~ /$value/) {$error=1;} }
elsif ($bed eq "BT") {
my ($v1,$v2) = split /\-/,$value;
if (($ergebnis > $v1) and ($ergebnis < $v2)) {$error=1;}
}
elsif ($bed eq "NBT") {
my ($v1,$v2) = split /\-/,$value;
if (($ergebnis <= $v1) or ($ergebnis >= $v2)) {$error=1;}
}
else {
alert_log($todo,$position,"Ungültiger Vergleich im Check. Nur RE,(N)LT,GT,EQ,BT erlaubt.");
}
}
return $error;
}
sub get_snmp_value {
my ($todo,$position) = @_;
my ($host,$community,$port,$oid,$result,$ret);
my $temp = 1;
$host = $c2->{'todo'}->{$todo}->{'hosts'}->{'ip'};
if (ping($host)) {
$community = $c2->{'todo'}->{$todo}->{'hosts'}->{'ro_community'};
$port = $c2->{'todo'}->{$todo}->{'hosts'}->{'snmp_port'};
$oid = $c2->{'todo'}->{$todo}->{'services'}->{$position}->{'variable'};
my ($session,$error) = Net::SNMP->session(Hostname => "$host", Community => "$community", Port => $port);
$result = $session->get_request("$oid");
$session->close;
}
else {
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'error'} = 1;
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ergebnis'} = $c2->{'error'}->{2}->{'error_text'};
; # Not reachable
alert_log ($todo,$position,"interner Fehler im Dienst (snmp request)");
$temp=0;
}
if ($result->{"$oid"} eq "") {
if ($temp) {
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'error'} = 1;
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ergebnis'} = $c2->{'error'}->{3}->{'error_text'};
; # no snmp response
alert_log ($todo,$position,"interner Fehler im Dienst (ping)");
}
}
else {
if ($temp) {
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'error'} = 0;
if ($oid =~ /1.3.6.1.2.1.1.3.0/) { # SYS_UPTIME
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ergebnis'} = sys_uptime($result->{"$oid"});
}
else {
$c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ergebnis'} = $result->{"$oid"};
}
}
}
$ret = $c2->{'todo'}->{$todo}->{'services'}->{$position}->{'ergebnis'};
print " $todo, $position : $host $community $port $oid $ret\n";
return $ret;
}
sub sys_uptime {
my ($txt) = @_;
# 24.01 seconds
# 1 minute, 06.60
# 2 hours, 25:19.22
#print "$txt\n";
$txt =~ s/[a-z ]//g;
$txt =~ s/[.:-]/,/g;
#print "$txt\n";
my @array;
@array = split /,/,$txt;
while (@array < 5) {
@array = (0,@array);
}
$array[0] = $array[0] * 24 * 60 * 60;
$array[1] = $array[1] * 60 * 60;
$array[2] = $array[2] * 60;
my $tticks = ($array[0] + $array[1] + $array[2] + $array[3])*100 + $array[4];
return $tticks;
}
sub ping {
my ($host) = @_;
my $pingtype = "icmp";
my $timeout = 1;
my $bytes = 32;
my $ok = 0;
my $ping = Net::Ping->new($pingtype,$timeout,$bytes);
if ($ping->ping($host,1)) {
$ok = 1;
}
return $ok;
}
sub get_time {
my %ts;
my $time_stamp;
($ts{"ss"},$ts{"mm"},$ts{"hh"},$ts{"dd"},$ts{"mon"},$ts{"yy"},$ts{"we"},$ts{"doy"},$ts{"st"})=localtime;
if ($ts{"ss"} < 10) { $ts{"ss"} = "0" . $ts{"ss"}; }
if ($ts{"mm"} < 10) { $ts{"mm"} = "0" . $ts{"mm"}; }
if ($ts{"hh"} < 10) { $ts{"hh"} = "0" . $ts{"hh"}; }
$time_stamp = "$ts{'hh'}" . ":" . "$ts{'mm'}" . ":" . "$ts{'ss'}";
return $time_stamp;
}
sub get_timestamp {
my %ts;
my $time_stamp;
($ts{"ss"},$ts{"mm"},$ts{"hh"},$ts{"dd"},$ts{"mon"},$ts{"yy"},$ts{"we"},$ts{"doy"},$ts{"st"})=localtime;
$time_stamp = $ts{'hh'} * 3600 + $ts{'mm'} * 60 + $ts{'ss'};
return $time_stamp;
}
sub get_date {
my (%ts,$ret);
($ts{"ss"},$ts{"mm"},$ts{"hh"},$ts{"dd"},$ts{"mon"},$ts{"yy"},$ts{"we"},$ts{"doy"},$ts{"st"})=localtime;
$ts{"yy"} += 1900;
$ts{"mon"} += 1;
if ($ts{"dd"} < 10) { $ts{"dd"} = "0" . $ts{"dd"}; }
if ($ts{"mon"} < 10) { $ts{"mon"} = "0" . $ts{"mon"}; }
$ret = "$ts{'dd'}" . "-" . "$ts{'mon'}" . "-" . "$ts{'yy'}";
return $ret;
}
sub read_database {
my ($sth,$ref,$sth1,$ref1,$sth2,$ref2);
foreach my $todo ( keys %{$c2->{'todo'}} ) {
$sth = $dbh->prepare("select ind from todos where t_active='1'");
$sth->execute;
# print "$todo:";
while ($ref = $sth->fetchrow_arrayref()) {
my $found = 0;
if ($ref->[0] == $todo) {
$found=1;
}
unless ($found) {
delete $c2->{'todo'}->{$todo};
}
}
}
# 8
$sth = $dbh->prepare("select ind,t_host,t_service,t_check,t_alert from todos where t_active='1'");
$sth->execute;
while ($ref = $sth->fetchrow_arrayref()) { # aktive todos durchlaufen
read_conf("$ref->[0]","hosts","$ref->[1]"); #Hosts lesen
read_conf("$ref->[0]","alerts","$ref->[4]"); #Alerts lesen
read_conf("$ref->[0]","checks","$ref->[3]"); #Checks lesen
# Services lesen
$sth1 = $dbh->prepare("select position from services where service_ind = '$ref->[2]'");
$sth1->execute;
while ($ref1 = $sth1->fetchrow_arrayref()) { # Einzelne Felder der Tabellen durchlaufen
$sth2 = $dbh->prepare("show fields from services");
$sth2->execute;
while ($ref2 = $sth2->fetchrow_arrayref()) {
$c2->{"todo"}->{"$ref->[0]"}->{"services"}->{"$ref1->[0]"}->{"$ref2->[0]"} = get_vari("services", "$ref2->[0]", "service_ind = '$ref->[2]' and position = '$ref1->[0]'");
}
}
}
#Konfig lesen
#$dbh1 = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
$sth1 = $dbh->prepare("show fields from conf");
$sth1->execute;
while ($ref1 = $sth1->fetchrow_arrayref()) { # Einzelne Felder der Tabellen durchlaufen
$c2->{"conf"}->{"$ref1->[0]"} = get_vari("conf", "$ref1->[0]", "active = '1'");
}
# Error lesen
#$dbh1 = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
$sth1 = $dbh->prepare("select error_number from errors");
$sth1->execute;
while ($ref1 = $sth1->fetchrow_arrayref()) {
#$error_nr = $ref1->[0];
#$dbh2 = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
$sth2 = $dbh->prepare("show fields from errors");
$sth2->execute;
while ($ref2 = $sth2->fetchrow_arrayref()) { # Einzelne Felder der Tabellen durchlaufen
#$field = $ref2->[0];
$c2->{"error"}->{"$ref1->[0]"}->{"$ref2->[0]"} = get_vari("errors", "$ref2->[0]", "error_number = '$ref1->[0]'");
}
}
1;
}
sub get_vari {
my ($table,$variable,$bedingung) = @_;
my $ret;
my $sth = $dbh->prepare("select $variable from $table where $bedingung");
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
$ret = $ref->[0];
}
return $ret;
}
sub read_conf {
my ($ind,$table,$value) = @_;
my $sth = $dbh->prepare("show fields from $table");
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
$c2->{"todo"}->{"$ind"}->{"$table"}->{"$ref->[0]"} = get_vari("$table", "$ref->[0]", "ind = '$value'");
}
}
sub clear_line {
# Entfernt Zeilenendezeichen
my ($line) = @_;
chomp $line;
$line = delete_front_back_spaces ($line);
return $line;
}
sub delete_front_back_spaces {
# Entfernt Leerzeichen am Zeilenanfang und Zeilenende
my ($line) = @_;
unless ($line eq "") {
$line=~s/^ *//g;
$line=~s/ *$//g;
}
return $line;
}

View File

@@ -0,0 +1,87 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $ind = param('ind');
my $akt = param('akt');
my $deakt = param('deakt');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Todo aktivieren/deaktivieren</u></b><br><br>\n";
if ($ind eq "") {
my $sth = $dbh->prepare("select ind,t_host,t_service,t_check,t_alert,t_description from todos order by 'ind'");
$sth->execute;
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<form action='chg_todo.pl'>\n";
print "<tr>\n";
print "<td><input type='hidden' name='ind' value='$ref->[0]'></td>\n";
#HOST
my $sth_host = $dbh->prepare("select hostname,ip from hosts where ind='$ref->[1]'");
$sth_host->execute;
while (my $ref_host = $sth_host->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_host->[0] ($ref_host->[1])'></td>\n";
}
#SERVICE
my $sth_desc = $dbh->prepare("select distinct description from services where service_ind='$ref->[2]'");
$sth_desc->execute;
while (my $ref_desc = $sth_desc->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_desc->[0]'></td>\n";
}
#CHECK
my $sth_check = $dbh->prepare("select description from checks where ind='$ref->[3]'");
$sth_check->execute;
while (my $ref_check = $sth_check->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_check->[0]'></td>\n";
}
#ALERT
my $sth_alert = $dbh->prepare("select description from alerts where ind='$ref->[4]'");
$sth_alert->execute;
while (my $ref_alert = $sth_alert->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_alert->[0]'></td>\n";
}
#DESCRIPTION
print "<td><input type='text' readonly value='$ref->[5]'></td>\n";
print "<td><input type='submit' name='akt' value='aktivieren'></td>\n";
print "<td><input type='submit' name='deakt' value='deaktivieren'></td>\n";
print "</tr>\n";
print "</form>\n";
}
print "</table>\n";
}
else {
#$dbh->do("delete from todos where ind='$del'");
if ($akt eq "aktivieren") {
$dbh->do("update todos set t_active = '1' where ind ='$ind'");
print "<br>Todo aktiviert!\n";
}
if ($deakt eq "deaktivieren") {
$dbh->do("update todos set t_active = '0' where ind ='$ind'");
print "<br>Todo deaktiviert!\n";
}
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,44 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $ind = param('ind');
my $del = param('del');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Alarm entfernen</u></b>\n";
if ($del eq "") {
my $sth = $dbh->prepare("select ind,description,alert_type from alerts order by 'alert_typ','description'");
$sth->execute;
print "<form action='del_alert.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td><input type='radio' name='del' value='$ref->[0]'></td>\n";
print "<td><input type='text' readonly value='$ref->[1]'></td>\n";
print "<td><input type='text' readonly value='$ref->[2]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' value='Löschen'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
$dbh->do("delete from alerts where ind='$del'");
print "<br>Löschen durchgeführt!";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,16 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "</head>\n";
print "<body>\n";
$dbh->do("delete from alerts_log");
print "<br><br>Alerts_log geleert!\n";
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,45 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $ind = param('ind');
my $del = param('del');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Check entfernen</u></b>\n";
if ($del eq "") {
my $sth = $dbh->prepare("select ind,description,beding,wert from checks order by 'description'");
$sth->execute;
print "<form action='del_check.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td><input type='radio' name='del' value='$ref->[0]'></td>\n";
print "<td><input type='text' readonly value='$ref->[1]'></td>\n";
print "<td><input type='text' readonly value='$ref->[2]'></td>\n";
print "<td><input type='text' readonly value='$ref->[3]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' value='Löschen'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
$dbh->do("delete from checks where ind='$del'");
print "<br>Löschen durchgeführt!";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,45 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $ind = param('ind');
my $del = param('del');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Host entfernen</u></b>\n";
if ($del eq "") {
my $sth = $dbh->prepare("select ind,description,hostname,ip from hosts order by 'hostname'");
$sth->execute;
print "<form action='del_host.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td><input type='radio' name='del' value='$ref->[0]'></td>\n";
print "<td><input type='text' readonly value='$ref->[1]'></td>\n";
print "<td><input type='text' readonly value='$ref->[2]'></td>\n";
print "<td><input type='text' readonly value='$ref->[3]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' value='Löschen'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
$dbh->do("delete from hosts where ind='$del'");
print "<br>Löschen durchgeführt!";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,74 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $ind = param('ind');
my $del = param('del');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Todo entfernen</u></b>\n";
if ($del eq "") {
my $sth = $dbh->prepare("select ind,t_host,t_service,t_check,t_alert,t_description from todos order by 'ind'");
$sth->execute;
print "<form action='del_todo.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td><input type='radio' name='del' value='$ref->[0]'></td>\n";
#HOST
my $sth_host = $dbh->prepare("select hostname,ip from hosts where ind='$ref->[1]'");
$sth_host->execute;
while (my $ref_host = $sth_host->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_host->[0] ($ref_host->[1])'></td>\n";
}
#SERVICE
my $sth_desc = $dbh->prepare("select distinct description from services where service_ind='$ref->[2]'");
$sth_desc->execute;
while (my $ref_desc = $sth_desc->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_desc->[0]'></td>\n";
}
#CHECK
my $sth_check = $dbh->prepare("select description from checks where ind='$ref->[3]'");
$sth_check->execute;
while (my $ref_check = $sth_check->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_check->[0]'></td>\n";
}
#ALERT
my $sth_alert = $dbh->prepare("select description from alerts where ind='$ref->[4]'");
$sth_alert->execute;
while (my $ref_alert = $sth_alert->fetchrow_arrayref()) {
print "<td><input type='text' readonly value='$ref_alert->[0]'></td>\n";
}
#DESCRIPTION
print "<td><input type='text' readonly value='$ref->[5]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' value='Löschen'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
$dbh->do("delete from todos where ind='$del'");
print "<br>Löschen durchgeführt!";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,137 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $edit = param('edit');
my $edit1 = param('edit1');
my $descr=param('descr');
my $typ=param('typ');
my $mf=param('mf');
my $mt=param('mt');
my $se=param('se');
my $sg=param('sg');
my $ss=param('ss');
my $st=param('st');
my $sp=param('sp');
my $sc=param('sc');
my $sm=param('sm');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
#print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Alert editieren</u></b>\n";
if ($edit eq "") {
my $sth = $dbh->prepare("select ind,description,alert_type from alerts order by 'description'");
$sth->execute;
print "<form action='edit_alert.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td><input type='radio' name='edit' value='$ref->[0]'></td>\n";
print "<td><input type='text' readonly value='$ref->[1]'></td>\n";
print "<td><input type='text' readonly value='$ref->[2]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' name='edit1' value='Edit'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
if ($edit1 eq "Edit") {
my $sth = $dbh->prepare("select ind,description,alert_type,mail_from,mail_to,enterprise,generic,specific,destination,port,community,txt_msg from alerts where ind='$edit'");
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
print "<form action='edit_alert.pl'>\n";
print "<table border='1'>\n";
print "<tr>\n<td>Description</td>\n";
print "<td><input name='descr' type='text' value='$ref->[1]'></td>\n";
print "</tr>\n";
#ääää
print "<tr>\n";
print "<td>Typ</td>\n";
print "<td><select name='typ'>\n";
if ($ref->[2] eq "mail") {
print "<option value='snmp'>SNMP</option>\n";
print "<option selected value='mail'>MAIL</option>\n";
}
if ($ref->[2] eq "snmp") {
print "<option selected value='snmp'>SNMP</option>\n";
print "<option value='mail'>MAIL</option>\n";
}
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>Mail: from</td>\n";
print "<td><input name='mf' type='text' value='$ref->[3]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>Mail: to</td>\n";
print "<td><input name='mt' type='text' value='$ref->[4]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP: Enterprise</td>\n";
print "<td><input name='se' type='text' value='$ref->[5]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP: generic</td>\n";
print "<td><input name='sg' type='text' value='$ref->[6]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP: specific</td>\n";
print "<td><input name='ss' type='text' value='$ref->[7]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP: to</td>\n";
print "<td><input name='st' type='text' value='$ref->[8]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP: Port</td>\n";
print "<td><input name='sp' type='text' value='$ref->[9]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP: Community</td>\n";
print "<td><input name='sc' type='text' value='$ref->[10]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP+Mail: Nachricht</td>\n";
print "<td><input name='sm' type='text' value='$ref->[11]'></td>\n";
print "</tr>\n";
print "</table>\n";
print "<input type='submit' name='edit1' value='Speichern'>\n";
print "<input type='hidden' name='edit' value='$edit'>\n";
print "</form>\n";
}
}
if ($edit1 eq "Speichern") {
#$dbh->do("update hosts set description='$descr', hostname='$hostn', ip='$ipadd', rw_community='$rwcom', ro_community='$rocom', snmp_port='$snmpp' where ind='$edit'");
#$dbh->do(
$dbh->do("update alerts set description='$descr', alert_type='$typ', mail_from='$mf', mail_to='$mt', enterprise='$se', generic='$sg', specific='$ss', destination='$st', port='$sp', community='$sc', txt_msg='$sm' where ind='$edit'");
print "<br>Gespeichert\n";
}
#print "Löschen durchgeführt!";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,106 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $edit = param('edit');
my $edit1 = param('edit1');
my $descr=param('descr');
my $bedin=param('bedingung');
my $wert=param('wert');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
#print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Check editieren</u></b>\n";
if ($edit eq "") {
my $sth = $dbh->prepare("select ind,description,beding,wert from checks order by 'description'");
$sth->execute;
print "<form action='edit_check.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td><input type='radio' name='edit' value='$ref->[0]'></td>\n";
print "<td><input type='text' readonly value='$ref->[1]'></td>\n";
print "<td><input type='text' readonly value='$ref->[2]'></td>\n";
print "<td><input type='text' readonly value='$ref->[3]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' name='edit1' value='Edit'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
if ($edit1 eq "Edit") {
my $sth = $dbh->prepare("select ind,description,beding,wert from checks where ind='$edit'");
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
print "<form action='edit_check.pl'>\n";
print "<table border='1'>\n";
print "<tr>\n<td>Description</td>\n";
print "<td><input name='descr' type='text' value='$ref->[1]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>Prüfung</td>\n";
print "<td>";
print "<select name='bedingung' value='$ref->[2]'>\n";
my $seltxt="";
if ($ref->[2] eq "EQ") { $seltxt=" selected"; }
print "<option $seltxt>EQ</option>\n";
$seltxt="";
if ($ref->[2] eq "NEQ") { $seltxt=" selected"; }
print "<option $seltxt>NEQ</option>\n";
$seltxt="";
if ($ref->[2] eq "LT") { $seltxt=" selected"; }
print "<option $seltxt>LT</option>\n";
$seltxt="";
if ($ref->[2] eq "NLT") { $seltxt=" selected"; }
print "<option $seltxt>NLT</option>\n";
$seltxt="";
if ($ref->[2] eq "GT") { $seltxt=" selected"; }
print "<option $seltxt>GT</option>\n";
$seltxt="";
if ($ref->[2] eq "NGT") { $seltxt=" selected"; }
print "<option $seltxt>NGT</option>\n";
$seltxt="";
if ($ref->[2] eq "BT") { $seltxt=" selected"; }
print "<option $seltxt>BT</option>\n";
$seltxt="";
if ($ref->[2] eq "NBT") { $seltxt=" selected"; }
print "<option $seltxt>NBT</option>\n";
$seltxt="";
if ($ref->[2] eq "RE") { $seltxt=" selected"; }
print "<option $seltxt>RE</option>\n";
print "</select>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>Vergleichswert</td>\n";
print "<td><input name='wert' type='text' value='$ref->[3]'></td>\n";
print "</tr>\n";
print "</table>\n";
print "<input type='submit' name='edit1' value='Speichern'>\n";
print "<input type='hidden' name='edit' value='$edit'>\n";
print "</form>\n";
}
}
if ($edit1 eq "Speichern") {
$dbh->do("update checks set description='$descr', beding='$bedin', wert='$wert' where ind='$edit'");
#print "update checks set description='$descr', beding='$bedin', wert='$wert' where ind='$edit'";
print "<br>Gespeichert\n";
}
#print "Löschen durchgeführt!";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,84 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $edit = param('edit');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
my $ci=param('ci');
my $we=param('we');
my $wri=param('wri');
my $url=param('url');
my $urla=param('urla');
my $path=param('path');
my $roi=param('roi');
my $wt=param('wt');
my $starttime=param('starttime');
my $stoptime=param('stoptime');
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
#print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Konfig editieren</u></b>\n";
if ($edit eq "") {
my $sth = $dbh->prepare("select check_intervall,web_enable,web_refresh_intervall,web_link,web_template,runs_on_ip,config_url,start_time,stop_time,index_dir from conf");
$sth->execute;
print "<form action='edit_conf.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td>Check Intervall</td><td><input name='ci' type='text' value='$ref->[0]'></td>\n";
print "<tr></tr>\n";
print "<td>Web enabled</td>\n";
print "<td><select name='we'>\n";
if ($ref->[1] eq "1") {
print "<option selected value='1'>Ja</option>\n";
print "<option value='0'>Nein</option>\n";
}
if ($ref->[1] eq "0") {
print "<option value='1'>Ja</option>\n";
print "<option selected value='0'>Nein</option>\n";
}
print "</td>\n";
print "<tr></tr>\n";
print "<td>Web refresh Intervall</td><td><input name='wri' type='text' value='$ref->[2]'></td>\n";
print "<tr></tr>\n";
print "<td>Web URL</td><td><input size='40' name='url' type='text' value='$ref->[3]'></td>\n";
print "<tr></tr>\n";
print "<td>Web Template</td><td><input size='60' name='wt' type='text' value='$ref->[4]'></td>\n";
print "<tr></tr>\n";
print "<td>Web-Page</td><td><input size='60' name='path' type='text' value='$ref->[9]'></td>\n";
print "<tr></tr>\n";
print "<td>Läuft auf IP</td><td><input name='roi' type='text' value='$ref->[5]'></td>\n";
print "<tr></tr>\n";
print "<td>Web Admin URL</td><td><input name='urla' size='40' type='text' value='$ref->[6]'></td>\n";
print "<tr></tr>\n";
print "<td>Startzeit</td><td><input name='starttime' size='10' type='text' value='$ref->[7]'></td>\n";
print "<tr></tr>\n";
print "<td>Stopzeit</td><td><input name='stoptime' size='10' type='text' value='$ref->[8]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' name='edit' value='Speichern'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
if ($edit eq "Speichern") {
$dbh->do("update conf set index_dir='$path',check_intervall='$ci',web_enable='$we',web_refresh_intervall='$wri',web_link='$url',web_template='$wt',runs_on_ip='$roi',config_url='$urla',start_time='$starttime',stop_time='$stoptime' where active='1'");
#print "update conf set check_intervall='$ci',web_enable='$we',web_refresh_intervall='$wri',web_link='$url',web_template='$wt',runs_on_ip='$roi',config_url='$urla' where active='1'";
# where active='1'
print "<br><br>Gespeichert\n";
}
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,91 @@
#!/bin/perl
use strict;
use mysql;
use CGI qw(:standard);
my $edit = param('edit');
my $edit1 = param('edit1');
my $descr=param('descr');
my $hostn=param('hostname');
my $ipadd=param('ip');
my $rocom=param('roc');
my $rwcom=param('rwc');
my $snmpp=param('port');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Host editieren</u></b>\n";
if ($edit eq "") {
my $sth = $dbh->prepare("select ind,description,hostname,ip from hosts order by 'hostname'");
$sth->execute;
print "<form action='edit_host.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr>\n";
print "<td><input type='radio' name='edit' value='$ref->[0]'></td>\n";
print "<td><input type='text' readonly value='$ref->[1]'></td>\n";
print "<td><input type='text' readonly value='$ref->[2]'></td>\n";
print "<td><input type='text' readonly value='$ref->[3]'></td>\n";
print "</tr>\n";
}
print "<tr><td></td>\n<td><input type='submit' name='edit1' value='Edit'></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else {
if ($edit1 eq "Edit") {
my $sth = $dbh->prepare("select ind,description,hostname,ip,rw_community,ro_community,snmp_port from hosts where ind='$edit'");
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
print "<form action='edit_host.pl'>\n";
print "<table border='1'>\n";
print "<tr>\n<td>Description</td>\n";
print "<td><input name='descr' type='text' value='$ref->[1]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>Hostname</td>\n";
print "<td><input name='hostname' type='text' value='$ref->[2]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>IP</td>\n";
print "<td><input name='ip' type='text' value='$ref->[3]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>RO-community</td>\n";
print "<td><input name='roc' type='text' value='$ref->[5]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>RW-community</td>\n";
print "<td><input name='rwc' type='text' value='$ref->[4]'></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td>SNMP-Port</td>\n";
print "<td><input name='port' type='text' value='$ref->[6]'></td>\n";
print "</tr>\n";
print "</table>\n";
print "<input type='submit' name='edit1' value='Speichern'>\n";
print "<input type='hidden' name='edit' value='$edit'>\n";
print "</form>\n";
}
}
if ($edit1 eq "Speichern") {
$dbh->do("update hosts set description='$descr', hostname='$hostn', ip='$ipadd', rw_community='$rwcom', ro_community='$rocom', snmp_port='$snmpp' where ind='$edit'");
#$dbh->do(
print "<br>Gespeichert\n";
}
#print "Löschen durchgeführt!";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,11 @@
<html>
<head>
<title>Admin</title>
</head>
<body>
<b><u>Todo editieren</u></b><br><br>
Bitte Todo löschen und einen neuen anlegen!<br><br>
Falls der alte Todo evtl. noch einmal gebraucht werden sollte,
lässt sich dieser auch vorübergehend deaktivieren.
</body>
</html>

View File

@@ -0,0 +1,9 @@
<html>
<head>
<title>Administration</title>
</head>
<frameset cols='230,*' rows='100%' border="0" frameborder="1" framespacing="0">
<frame src="links.html" name='links' scrolling="Option" noresize>
<frame src='rechts.html' name='rechts'>
</frameset>
</html>

View File

@@ -0,0 +1,40 @@
<html>
<head>
<title>Admin</title>
</head>
<body>
<a href="admin.html" target='rechts'>Administration</a><br>
<br>
<a href="alerts_log.pl" target='rechts'>Alarme</a><br>
<br>
<a href="edit_conf.pl" target='rechts'>Konfig editieren</a><br>
<br>
<a href="new_host.html" target='rechts'>Host hinzufügen</a><br>
<a href="del_host.pl" target='rechts'>Host entfernen</a><br>
<a href="edit_host.pl" target='rechts'>Host editieren</a><br>
<br>
<a href="new_service.html" target='rechts'>Dienst hinzufügen</a><br>
<a href="del_service.pl" target='rechts'>Dienst entfernen</a><br>
<a href="edit_service.pl" target='rechts'>Dienst editieren</a><br>
<br>
<a href="new_check.html" target='rechts'>Check hinzufügen</a><br>
<a href="del_check.pl" target='rechts'>Check entfernen</a><br>
<a href="edit_check.pl" target='rechts'>Check editieren</a><br>
<br>
<a href="new_alert.html" target='rechts'>Alarm hinzufügen</a><br>
<a href="del_alert.pl" target='rechts'>Alarm entfernen</a><br>
<a href="edit_alert.pl" target='rechts'>Alarm editieren</a><br>
<br>
<a href="new_todo.pl" target='rechts'>Todo hinzufügen</a><br>
<a href="del_todo.pl" target='rechts'>Todo entfernen</a><br>
<a href="edit_todo.html" target='rechts'>Todo editieren</a><br>
<a href="chg_todo.pl" target='rechts'>Todo aktivieren/deaktivieren</a><br>
</body>
</html>

View File

@@ -0,0 +1,66 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Alarm hinzufügen</title>
</head>
<body>
<b><u>Alarm hinzufügen</u></b>
<form action="save_alert.pl">
<table border="1">
<tr>
<td>Description</td>
<td><input name="descr" type="text" value=""></td>
</tr>
<tr>
<td>Typ</td>
<td>
<select name="typ">
<option value="snmp">SNMP</option>
<option value="mail">MAIL</option>
</select>
</td>
</tr>
<tr>
<td>Mail: from</td>
<td><input name="mfrom" type="text" value=""></td>
</tr>
<tr>
<td>Mail: to</td>
<td><input name="mto" type="text" value=""></td>
</tr>
<tr>
<td>SNMP: Enterprise</td>
<td><input name="enterprise" type="text" value="1.3.6.1.4.1.2222"></td>
</tr>
<tr>
<td>SNMP: generic</td>
<td><input name="generic" type="text" value="6"></td>
</tr>
<tr>
<td>SNMP: specific</td>
<td><input name="specific" type="text" value=""></td>
</tr>
<tr>
<td>SNMP: to</td>
<td><input name="sto" type="text" value=""></td>
</tr>
<tr>
<td>SNMP: Port</td>
<td><input name="port" type="text" value="162"></td>
</tr>
<tr>
<td>SNMP: Community</td>
<td><input name="comm" type="text" value="public"></td>
</tr>
<tr>
<td>SNMP+Mail: Nachricht</td>
<td><input name="msg" type="text" value="Fehler!"></td>
</tr>
</table>
<input type="submit" value="speichern">
</form>
</body>
</html>

View File

@@ -0,0 +1,41 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Check hinzufügen</title>
</head>
<body>
<b><u>Check hinzufügen</u></b>
<form action="save_check.pl">
<table border="1">
<tr>
<td>Description</td>
<td><input name="descr" type="text" value=""></td>
</tr>
<tr>
<td>Prüfung</td>
<td>
<select name="if">
<option>EQ</option>
<option>NEQ</option>
<option>LT</option>
<option>NLT</option>
<option>GT</option>
<option>NGT</option>
<option>BT</option>
<option>NBT</option>
<option>RE</option>
</select>
</td>
</tr>
<tr>
<td>Vergleichswert</td>
<td><input name="value" type="text" value=""></td>
</tr>
</table>
<input type="submit" value="speichern">
</form>
</body>
</html>

View File

@@ -0,0 +1,39 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Host hinzufügen</title>
</head>
<body>
<b><u>Host hinzufügen</u></b>
<form action="save_host.pl">
<table border="1">
<tr>
<td>Description</td>
<td><input name="descr" type="text" value=""></td>
</tr>
<tr>
<td>Hostname</td>
<td><input name="hostname" type="text" value=""></td>
</tr>
<tr>
<td>IP</td>
<td><input name="ip" type="text" value=""></td>
</tr>
<tr>
<td>RO-community</td>
<td><input name="roc" type="text" value="public"></td>
</tr>
<tr>
<td>RW-community</td>
<td><input name="rwc" type="text" value=""></td>
</tr>
<tr>
<td>SNMP-Port</td>
<td><input name="port" type="text" value="161"></td>
</tr>
</table>
<input type="submit" value="speichern">
</form>
</body>
</html>

View File

@@ -0,0 +1,81 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Dienst hinzufügen</title>
</head>
<body>
<b><u>Dienst hinzufügen</u></b>
<form action="save_service.pl">
<table border="1">
<tr>
<td>Description</td>
<td><input name="descr" type="text" value=""></td>
</tr>
<tr>
<td>Service-Nummer</td>
<td><input name="sid" type="text" value=""></td>
</tr>
<tr>
<td>Nummer im Dienst</td>
<td><input name="pid" type="text" value=""></td>
</tr>
<tr>
<td>Aufgabe</td>
<td>
<table>
<tr>
<td><input checked name="check" type="radio" value="ping"></td>
<td>P</td>
<td>
<select name="ping">
<option>IP</option>
<option>HOST</option>
</select>
</td>
</tr>
<tr>
<td><input name="check" type="radio" value="snmp"></td>
<td>S</td>
<td><input name="snmp" type="text" value=""></td>
</tr>
<tr>
<td><input name="check" type="radio" value="konst"></td>
<td>K</td>
<td><input name="konst" type="text" value=""></td>
</tr>
<tr>
<td><input name="check" type="radio" value="calc"></td>
<td>C</td>
<td>
<input name="calc1" type="text" value="">
<select name="calc2">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input name="calc3" type="text" value="">
</td>
</tr>
<tr>
<td><input name="check" type="radio" value="result"></td>
<td>R</td>
<td>
<select name="result1">
<option>A</option>
<option>R</option>
</select>-
<input name="result2" type="text" value=""></td>
</tr>
</table>
</td>
</tr>
</table>
<input type="submit" value="speichern">
</body>
</html>

View File

@@ -0,0 +1,94 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $gruppe = param('gruppe');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
my ($sth,$ref);
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
#print "td { font-size:10pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<b><u>Todo hinzufügen</u></b>\n";
print "<form action='save_todo.pl'>\n";
print " <table border='1'>\n";
print " <tr>\n";
print " <td>Host</td>\n";
print " <td>Service</td>\n";
print " <td>Prüfung</td>\n";
print " <td>Alarm</td>\n";
print " <td>Aktiv?</td>\n";
print " <td>Beschreibung</td>\n";
print " </tr>\n";
print " <tr>\n";
print " <td>\n";
print " <select name='host'>\n";
# hosts
$sth = $dbh->prepare("select ind,hostname,ip from hosts order by hostname");
$sth->execute;
while ($ref = $sth->fetchrow_arrayref()) {
print " <option value='$ref->[0]'><font size='-1'>$ref->[1] ($ref->[2])</font></option>\n";
}
print " </select>\n";
print " </td>\n";
print " <td>\n";
print " <select name='service'>\n";
# services
$sth = $dbh->prepare("select distinct service_ind, description from services");
$sth->execute;
while ($ref = $sth->fetchrow_arrayref()) {
print " <option value='$ref->[0]'>$ref->[1]</option>\n";
}
print " </select>\n";
print " </td>\n";
print " <td>\n";
print " <select name='check'>\n";
#checks
$sth = $dbh->prepare("select description,beding,wert,ind from checks");
$sth->execute;
while ($ref = $sth->fetchrow_arrayref()) {
print " <option value='$ref->[3]'>$ref->[0] ($ref->[1] $ref->[2])</option>\n";
}
print " </select>\n";
print " </td>\n";
print " <td>\n";
print " <select name='alert'>\n";
# alerts
$sth = $dbh->prepare("select description,alert_type,ind from alerts");
$sth->execute;
while ($ref = $sth->fetchrow_arrayref()) {
print " <option value='$ref->[2]'>$ref->[0] ($ref->[1])</option>\n";
}
print " </select>\n";
print " </td>\n";
print " <td><select name='active'><option value='1'>ja</option><option value='0'>nein</option></select></td>\n";
print " <td><input maxlength='255' name='descr' type='text' value=''></td>\n";
print " </tr>\n";
print " </table>\n";
print " <input type='submit' value='speichern'>\n";
print "</form>\n";
print "\n";
# $sth = $dbh->prepare($sel);
# $sth->execute;
# while ($ref = $sth->fetchrow_arrayref()) {
# print "$ref->[1], $ref->[2] $ref->[3] <a target='rechts' href='forum_rechts.pl?index=$ref->[0]'>$ref->[4]</a>";
# }
print "</body>\n</html>\n";

View File

@@ -0,0 +1,47 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $save=param('save');
my $dd = param('day');
my $mm = param('month');
my $yy = param('year');
my $ftag = param('ftag');
my $datum;
print header();
print "<html>\n";
print "<head>\n";
print "</head>\n";
print "<body>\n";
print "Datumsformat dd-mm-yyyy. Ist dd oder mm kleiner als 10,<br>muß eine führende 0 eingegeben werden.<br>\n";
print "Bei Eingabe eines ungültigen Datums wird 00-00-0000 gespeichert!<br><br>\n";
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
if ($save eq "") {
my $sth = $dbh->prepare("select description,datum from not_run_on order by datum");
$sth->execute;
#print "<form action='notrunon.pl'>\n";
print "<table>\n";
while (my $ref = $sth->fetchrow_arrayref()) {
my ($yy,$mm,$dd) = split /-/,$ref->[1];
print "<tr><form action='notrunon.pl'><input type='hidden' name='ftag' value='$ref->[0]'><td>$ref->[0]</td><td><input size='1' type='text' name='day' value='$dd'></td><td><input size='1' type='text' name='month' value='$mm'></td><td><input size='3' type='text' name='year' value='$yy'></td><td><input type='submit' name='save' value='Speichern'></td></form></tr>\n";
}
print "</table>\n";
#print "</form>\n";
}
if ($save eq "Speichern") {
$datum="$yy" . "-" . "$mm" . "-" . "$dd";
$dbh->do("update not_run_on set datum='$datum' where description='$ftag'");
print "<br><br>Gespeichert\n";
#print "$ftag $dd $mm $yy";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title>Admin</title>
</head>
<body>
Eingabeseite
</body>
</html>

101
Perl CGI C2/admin/runon.pl Normal file
View File

@@ -0,0 +1,101 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $save=param('save');
my $so = param('Sonntag');
my $mo = param('Montag');
my $di = param('Dienstag');
my $mi = param('Mittwoch');
my $don = param('Donnerstag');
my $fr = param('Freitag');
my $sa = param('Samstag');
print header();
print "<html>\n";
print "<head>\n";
print "</head>\n";
print "<body>\n";
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
if ($save eq "") {
print "<form action='runon.pl'>\n";
print "An welchen Tagen sollen Checks durchgeführt werden?\n";
print "<table>\n";
my $sth = $dbh->prepare("select description,day,value from run_on order by 'day'");
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref()) {
print "<tr><td>$ref->[0]</td>\n";
print "<td>";
if ($ref->[2] == '1') { print "<input checked type='checkbox' name='$ref->[0]'>"; }
if ($ref->[2] == '0') { print "<input type='checkbox' name='$ref->[0]'>"; }
print "</td></tr>\n";
}
print "</table>\n";
print "<input type='hidden' name='save' value='save'>\n";
print "<input type='submit' value='Speichern'>\n";
print "</form>\n";
}
if ($save eq "save") {
if ($so) {
$dbh->do("update run_on set value = 1 where description = 'Sonntag'");
}
else {
$dbh->do("update run_on set value = 0 where description = 'Sonntag'");
}
if ($mo) {
$dbh->do("update run_on set value = 1 where description = 'Montag'");
}
else {
$dbh->do("update run_on set value = 0 where description = 'Montag'");
}
if ($di) {
$dbh->do("update run_on set value = 1 where description = 'Dienstag'");
}
else {
$dbh->do("update run_on set value = 0 where description = 'Dienstag'");
}
if ($mi) {
$dbh->do("update run_on set value = 1 where description = 'Mittwoch'");
}
else {
$dbh->do("update run_on set value = 0 where description = 'Mittwoch'");
}
if ($don) {
$dbh->do("update run_on set value = 1 where description = 'Donnerstag'");
}
else {
$dbh->do("update run_on set value = 0 where description = 'Donnerstag'");
}
if ($fr) {
$dbh->do("update run_on set value = 1 where description = 'Freitag'");
}
else {
$dbh->do("update run_on set value = 0 where description = 'Freitag'");
}
if ($sa) {
$dbh->do("update run_on set value = 1 where description = 'Samstag'");
}
else {
$dbh->do("update run_on set value = 0 where description = 'Samstag'");
}
print "<br><br>Gespeichert\n";
}
print "</body>\n";
print "</html>\n";

View File

@@ -0,0 +1,34 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $v0 = param('descr');
my $v1 = param('typ');
my $v2 = param('mfrom');
my $v3 = param('mto');
my $v4 = param('enterprise');
my $v5 = param('generic');
my $v6 = param('specific');
my $v7 = param('sto');
my $v8 = param('port');
my $v9 = param('comm');
my $v10 = param('msg');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
$dbh->do("insert into alerts (description,alert_type,mail_from,mail_to,enterprise,specific,generic,destination,port,community,txt_msg) values ('$v0','$v1','$v2','$v3','$v4','$v6','$v5','$v7','$v8','$v9','$v10')");
print "</body>\n</html>\n";

View File

@@ -0,0 +1,26 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $v0 = param('descr');
my $v1 = param('if');
my $v2 = param('value');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
$dbh->do("insert into checks (description,beding,wert) values ('$v0','$v1','$v2')");
print "</body>\n</html>\n";

View File

@@ -0,0 +1,29 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $v0 = param('descr');
my $v1 = param('hostname');
my $v2 = param('ip');
my $v3 = param('roc');
my $v4 = param('rwc');
my $v5 = param('port');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
$dbh->do("insert into hosts (description,hostname,ip,ro_community,rw_community,snmp_port) values ('$v0','$v1','$v2','$v3','$v4','$v5')");
print "</body>\n</html>\n";

View File

@@ -0,0 +1,57 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $check=param('check');
my $v0 = param('descr');
my $v1 = param('sid');
my $v2 = param('pid');
my $ping=param('ping');
my $snmp=param('snmp');
my $konst=param('konst');
my $calc1=param('calc1');
my $calc2=param('calc2');
my $calc3=param('calc3');
my $result1=param('result1');
my $result2=param('result2');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
if ($check eq "ping") {
$dbh->do("insert into services (description,service_ind,position,todo,variable) values ('$v0','$v1','$v2','P','$ping')");
}
elsif ($check eq "snmp") {
$dbh->do("insert into services (description,service_ind,position,todo,variable) values ('$v0','$v1','$v2','S','$snmp')");
}
elsif ($check eq "konst") {
$dbh->do("insert into services (description,service_ind,position,todo,variable) values ('$v0','$v1','$v2','K','$konst')");
}
elsif ($check eq "calc") {
my $calc = "$calc1" . "$calc2" . "$calc3";
$dbh->do("insert into services (description,service_ind,position,todo,variable) values ('$v0','$v1','$v2','C','$calc')");
}
elsif ($check eq "result") {
my $result = "$result1" . "-" . "$result2";
$dbh->do("insert into services (description,service_ind,position,todo,variable) values ('$v0','$v1','$v2','R','$result')");
}
# $dbh->do("insert into alerts (description,alert_type,mail_from,mail_to,enterprise,specific,generic,destination,port,community,txt_msg) values ('$v0','$v1','$v2','$v3','$v4','$v6','$v5','$v7','$v8','$v9','$v10')");
print "</body>\n</html>\n";

View File

@@ -0,0 +1,29 @@
#!/bin/perl
use Mysql;
use strict;
use CGI qw(:standard);
my $host = param('host');
my $service = param('service');
my $alert = param('alert');
my $check = param('check');
my $descr = param('descr');
my $active = param('active');
my $dbh = DBI->connect("DBI:mysql:database=c2;host=localhost",'root','', {RaiseError => 1});
my ($sth,$ref);
print header();
print "<html>\n";
print "<head>\n";
print "<style type='text/css'>\n";
print "select { font-size:8pt }\n";
#print "td { font-size:10pt }\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
$dbh->do("insert into todos (t_host,t_service,t_check,t_alert,t_active,t_description) values ('$host','$service','$check','$alert','$active','$descr')");
print "</body>\n</html>\n";