Skip to content

Commit

Permalink
added crontab file
Browse files Browse the repository at this point in the history
updated README
moved files default location to /etc/zabbix/scripts for scripts and /etc/zabbix/ for config
  • Loading branch information
v-zhuravlev committed Oct 28, 2016
1 parent bff71c1 commit ad9e793
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
30 changes: 21 additions & 9 deletions README.md
Expand Up @@ -35,18 +35,27 @@ There are numerous ways to install them:

##Copy scripts
```
cp zabbix_syslog_create_urls.pl /usr/local/bin/zabbix_syslog_create_urls.pl
chmod +x /usr/local/bin/zabbix_syslog_create_urls.pl
cp zabbix_syslog_create_urls.pl /etc/zabbix/scripts/zabbix_syslog_create_urls.pl
chmod +x /etc/zabbix/scripts/zabbix_syslog_create_urls.pl
cp zabbix_syslog_lkp_host.pl /etc/zabbix/scripts/zabbix_syslog_lkp_host.pl
chmod +x /etc/zabbix/scripts/zabbix_syslog_lkp_host.pl
cp zabbix_syslog_lkp_host.pl /usr/local/bin/zabbix_syslog_lkp_host.pl
chmod +x /usr/local/bin/zabbix_syslog_lkp_host.pl
mkdir /etc/zabbix/scripts/lib
cp lib/ZabbixAPI.pm /etc/zabbix/scripts/lib
cp zabbix_syslog.cfg /usr/local/etc/zabbix_syslog.cfg
sudo chown zabbix:zabbix /usr/local/etc/zabbix_syslog.cfg
sudo chmod 700 /usr/local/etc/zabbix_syslog.cfg
cp zabbix_syslog.cfg /etc/zabbix/zabbix_syslog.cfg
sudo chown zabbix:zabbix /etc/zabbix/zabbix_syslog.cfg
sudo chmod 700 /etc/zabbix/zabbix_syslog.cfg
```
edit `/etc/zabbix/zabbix_syslog.cfg`

##Copy crontab
Next file updates syslog map links once a day.Copy it into your zabbix-server
```
cp cron.d/zabbix_syslog_create_urls /etc/cron.d
```
edit `/usr/local/etc/zabbix_syslog.cfg`

##rsyslog
add file /etc/rsyslog.d/zabbix_rsyslog.conf with contents:
Expand All @@ -61,7 +70,7 @@ $template network-fmt,"%TIMESTAMP:::date-rfc3339% [%fromhost-ip%] %pri-text% %sy
:msg, contains, "password auth succeeded for 'ubnt' from ::ffff:10.2.0.21" ~
:msg, contains, "password auth succeeded for 'ubnt' from" ~
:msg, contains, "exit before auth: Exited normally" ~
if $fromhost-ip != '127.0.0.1' then ^/usr/local/bin/zabbix_syslog_lkp_host.pl;network-fmt
if $fromhost-ip != '127.0.0.1' then ^/etc/zabbix/scripts/zabbix_syslog_lkp_host.pl;network-fmt
if $fromhost-ip != '127.0.0.1' then /var/log/network.log;network-fmt
& ~
```
Expand All @@ -74,6 +83,9 @@ $UDPServerRun 514
...to allow UDP Reception from the network (also check your firewall for UDP/514 btw)

...and restart rsyslog
```
service rsyslog restart
```

##Import template
Import syslog template and attach it to hosts from which you expect syslog messages to come
Expand Down
3 changes: 3 additions & 0 deletions cron.d/zabbix_syslog_create_urls
@@ -0,0 +1,3 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin

0 1 * * * zabbix /etc/zabbix/scripts/zabbix_syslog_create_urls.pl 2>&1
13 changes: 10 additions & 3 deletions zabbix_syslog_create_urls.pl
Expand Up @@ -10,8 +10,14 @@
use Data::Dumper;
use Config::General;
use ZabbixAPI;
our $VERSION = 1.1;
my $conf = Config::General->new('/usr/local/etc/zabbix_syslog.cfg');
our $VERSION = 2.0;
my $conf;
$conf = eval {Config::General->new('/usr/local/etc/zabbix_syslog.cfg')};
if ($@) {
eval {$conf = Config::General->new('/etc/zabbix/zabbix_syslog.cfg')};
if ($@) {die "Please check that config file is available as /usr/local/etc/zabbix_syslog.cfg or /etc/zabbix/zabbix_syslog.cfg\n";}
}

my %Config = $conf->getall;

#Authenticate yourself
Expand All @@ -37,6 +43,7 @@
#put all mapelements into array @selements (so you can update map later!)
@selements = @{ $map->{selements} };

print "INFO: Checking map with mapid $map->{sysmapid}\n";
foreach my $selement (@selements) {
my $syslog_button_exists = 0;

Expand Down Expand Up @@ -109,7 +116,7 @@ sub get_syslogid_by_hostid {
my $params = {
output => ['itemid'],
hostids => $hostid,
search => { 'key_' => 'syslog' },
filter => {'key_' => 'syslog' },
limit => 1,
};
my $result = $zbx->do('item.get',$params);
Expand Down
7 changes: 6 additions & 1 deletion zabbix_syslog_lkp_host.pl
Expand Up @@ -19,7 +19,12 @@
my $CACHE_TIMEOUT = 600;
my $CACHE_DIR = '/tmp/zabbix_syslog_cache';

my $conf = Config::General->new('/usr/local/etc/zabbix_syslog.cfg');
my $conf;
$conf = eval {Config::General->new('/usr/local/etc/zabbix_syslog.cfg')};
if ($@) {
eval {$conf = Config::General->new('/etc/zabbix/zabbix_syslog.cfg')};
if ($@) {die "Please check that config file is available as /usr/local/etc/zabbix_syslog.cfg or /etc/zabbix/zabbix_syslog.cfg\n";}
}
my %Config = $conf->getall;

#Authenticate yourself
Expand Down

0 comments on commit ad9e793

Please sign in to comment.