forked from Unatine/Zabbix-Domain-Check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomaindiscover.pl
59 lines (39 loc) · 1.1 KB
/
domaindiscover.pl
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
#!/usr/bin/perl
use strict;
my $first = 1;
my $directory = '/var/cache/zabbix/domain.db';
my %hash = ();
open(FILE1, "/etc/zabbix/domain.list") || die "Error: $!\n";
opendir (DIR, $directory) or die $!;
print "{\n";
print "\t\"data\":[\n\n";
while (<FILE1>) {
my $domain = substr($_, 0, -1);
print ",\n" if not $first;
$first = 0;
print "\t{\n";
print "\t\t\"{#DOMAIN}\":\"$domain\"\n";
print "\t}";
# Create domain database file if dosnt exist
my $filename = "/var/cache/zabbix/domain.db/$domain";
unless(-e $filename) {
open my $fc, ">", $filename;
close $fc;
}
$hash{ $domain } = $filename;
}
print "\n\t]\n";
print "}\n";
# check file list and delete old domains.
while (my $file = readdir(DIR)) {
# Use a regular expression to ignore files beginning with a period or end ".tmp"
next if ($file =~ m/^\./);
next if ($file =~ m/\.tmp$/);
if(exists($hash{$file})){
}
else{
unlink "$directory/$file";
unlink "$directory/$file.tmp";
}
}
closedir(DIR);