10 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(/usr/local/nagios/create_maps.pl:11):
11: my $dbserver1 = "sxnue710";
DB<1> c 94
main::(/usr/local/nagios/create_maps.pl:94):
94: print FILE "}\n";
DB<2> n
main::(/usr/local/nagios/create_maps.pl:95):
95: foreach $hostname (sort keys %hosts)
96: {
DB<2> p $hostname
wbnue034
DB<3> n
main::(/usr/local/nagios/create_maps.pl:97):
97: print $hostname."\n";
DB<3> p $hostname
HASH(0x85df58c)
DB<4>
1
2
3
my $host = Host2->new($hostname, $net, $parents);
#hash{key} = $value
$hosts{$hostname} = $host;
1
2
3
4
5
6
7
8
9
10
main::(/usr/local/nagios/create_maps.pl:68):
68: my $host = Host2->new($hostname, $net, $parents);
DB<3> n
main::(/usr/local/nagios/create_maps.pl:70):
70: $hosts{$hostname} = $host;
DB<3> p $hostname
Rechner03
DB<4> p $host
Host2=HASH(0x83b4a9c)
DB<5>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl
use strict;
use DBI;
use lib "/usr/local/nagios";
use Host2;
use Switch;
my $dbserver1 = "dbserver1";
my $username1 = "test";
my $password1 = "test-pw";
my $db1 = "rechnerpool";
my $dbserver2 = "dbserver2";
my $username2 = "test";
my $password2 = "test-pc";
my $db2 = "switchpool";
my @dirs;
$dirs[0] = "/etc/nagios/objects/hosts/linux/";
$dirs[1] = "/etc/nagios/objects/hosts/netview/";
$dirs[2] = "/etc/nagios/objects/hosts/switches/";
$dirs[3] = "/etc/nagios/objects/hosts/windows/";
my $temp = "";
my $net = "";
my $parents = "";
my $hostname = "";
my $i = 0;
my %hosts = {};
my $dbh1 = DBI->connect("DBI:mysql:database=".$db1.";host=".$dbserver1, $username1, $password1);
my $dbh2 = DBI->connect("DBI:mysql:database=".$db2.";host=".$dbserver2, $username2, $password2);
my $mapdir = "/usr/local/nagios/share/nagvis/nagvis/etc/maps/";
foreach my $dir (@dirs)
{
open(DIR, "ls ".$dir."|");
while(<DIR>)
{
$parents = "";
$net = "";
$hostname = "";
$i = 0;
# $_ hat den inhalt Rechner000.cfg
$_ =~/([0-9a-zA-Z]*)\.*/;
$hostname = $1;
my $sth1 = $dbh1->prepare("SELECT netz FROM hosts WHERE hostname LIKE \"%".$hostname."%\"");
$sth1->execute();
while(my $ref1 = $sth1->fetchrow_hashref())
{
$net = $ref1->{klasse};
}
$sth1->finish();
my $sth2 = $dbh2->prepare("SELECT hostns FROM swports WHERE system LIKE \"%".$hostname."%\" AND system NOT LIKE \"%DUMMY%\"");
$sth2->execute();
while(my $ref2 = $sth2->fetchrow_hashref())
{
if($i == 0)
{
$parents = $ref2->{hostns};
$i++;
}
else
{
$parents .= ",".$ref2->{hostns};
}
}
my $host = Host2->new($hostname, $net, $parents);
#hash{key} = $value
$hosts{$hostname} = $host;
}
close(DIR);
}
my $x = 0;
my $y = 0;
my @nets = {};
$nets[0] = "NetzA";
$nets[1] = "NetzB";
$nets[2] = "NetzC";
for(my $i=0; $i < $#nets; $i++)
{
$x = 0;
$y = 0;
open(FILE, ">".$mapdir.$nets[$i].".cfg");
print FILE "define global {\n";
print FILE "usegdlibs=1\n";
print FILE "allowed_user=nagios\n";
print FILE "allowed_for_config=nagios\n";
print FILE "iconset=std_medium\n";
print FILE "map_image=grey.png\n";
print FILE "}\n";
foreach $hostname (sort keys %hosts)
{
print $hostname."\n";
$temp = $hosts{$hostname};
if($temp->get("net") eq $nets[$i])
{
print FILE "define host {\n";
print FILE "only_hard_states=1\n";
print FILE "recognize_services=1\n";
print FILE "backend_id=ndomy_1\n";
print FILE "host_name=".$temp->get("hostname")."\n";
print FILE "x=".$x."\n";
print FILE "y=".$y."\n";
print FILE "}\n";
$x+=40;
if($x%400 == 0)
{
$y+=25;
$x=0;
}
}
}
close(FILE);
}
system("chown wwwrun:www ".$mapdir."*");
system("chmod 0664 ".$mapdir."*");
$dbh1->disconnect();
$dbh2->disconnect();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Host2;
use Switch;
# Konstruktor
sub new
{
# Perl uebergibt zuert die Bezeichnung der Klasse
my $class = $_[0];
# aufbau eines assoziativen Arrays um Speicher zu Allokieren
my $this = {
hostname => $_[1],
net => $_[2],
parents => $_[3],
};
# this wird die Klasse zugeurdnete
bless $this, $class;
# gibt die Referenz auf this(Instanz) zurueck
return $this;
}
# fuegt eine Eigenschaft hinzu
sub set
{
# Referenz auf Instantz
my $this = shift;
# zu schriebende Variable
my $name = shift;
# Wert der Variable
my $value = shift;
# speichert Variable und Wert in der Instanz
$this->{$name} = $value;
}
# gibt eine Eigenschaft zurueck
sub get
{
# Referenz auf Instantz
my $this = shift;
# zu lesende Variable
my $name = shift;
# Rueckgabe des angefragten Werts
return $this->{$name};
}
1;
my %hash = {}
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash = {}; $hash{test} = 'hallo'; print Dumper \%hash;
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; $hash{test} = 'hallo'; print Dumper \%hash;
1 2 3 4 5
my @dirs; $dirs[0] = "/etc/nagios/objects/hosts/linux/"; $dirs[1] = "/etc/nagios/objects/hosts/netview/"; $dirs[2] = "/etc/nagios/objects/hosts/switches/"; $dirs[3] = "/etc/nagios/objects/hosts/windows/";
1 2
my $dir_base = "/etc/nagios/objects/hosts/"; my @dirs = ( $dir_base . "linux/", $dir_base . "netview/", $dir_base . "switches/", $dir_base . "windows/" );
1 2
my $sth1 = $dbh1->prepare("SELECT netz FROM hosts WHERE hostname LIKE \"%".$hostname."%\""); $sth1->execute();
1 2
my $sth1 = $dbh1->prepare("SELECT netz FROM hosts WHERE hostname LIKE ?"); $sth1->execute( '%' . $hostname . '%' );
my $sth1 = $dbh1->prepare( ... ) or die $dbh1->errstr;
1 2 3 4
my @nets = {}; $nets[0] = "NetzA"; $nets[1] = "NetzB"; $nets[2] = "NetzC";
my @nets = ("NetzA","NetzB","NetzC");
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
my $x = 0; my $y = 0; #... for(my $i=0; $i < $#nets; $i++) { $x = 0; $y = 0; open(FILE, ">".$mapdir.$nets[$i].".cfg"); print FILE "define global {\n"; print FILE "usegdlibs=1\n"; print FILE "allowed_user=nagios\n"; print FILE "allowed_for_config=nagios\n"; print FILE "iconset=std_medium\n"; print FILE "map_image=grey.png\n"; print FILE "}\n";
1 2 3 4 5 6 7 8 9 10 11 12 13
for my $net ( @nets ){ my $x = 0; my $y = 0; open(FILE, ">".$mapdir.$net.".cfg") or die $!; print FILE qq~define global { usegdlibs=1 allowed_user=nagios allowed_for_config=nagios iconset=std_medium map_image=grey.png } ~;
10 Einträge, 1 Seite |