Появилась задача следить за кучей Микротиков в Zabbix. Первым делом, скачал MIB с официального сайта Микротик, включил SNMP на тестовом устройстве и стал искать что мне интересно. К сожалению, многих интересных настроек найдено в SNMP не было, например, {rt}x-rate, {rt}-ccq и др. Зато в SNMP есть уровень signal-а :) Поэтому я набросал небольшой скрипт на Perl для получения данных о wlan-интерфейсах с Mikrotik.
http://github.com/dynax60/zabbix-scripts/blob/a149397e56b1b81d6515a6d3af04c757855ffea8/mktk.pl
На сервере Zabbix в /usr/local/etc/zabbix/zabbix_agentd.conf прописал (требуется перезапуск Zabbix-агента; если хотите посмотреть какие можно мониторить параметры, вызовите скрипт для начала без 3-го аргумента, т.е. mktk.sh IPaddress wlan-ifX):
UserParameter=mktk.frequency[*],mktk.sh $1 $2 frequency
UserParameter=mktk.tx-ccq[*],mktk.sh $1 $2 tx-ccq
UserParameter=mktk.rx-ccq[*],mktk.sh $1 $2 rx-ccq
UserParameter=mktk.signal[*],mktk.sh $1 $2 signal
UserParameter=mktk.noise-floor[*],mktk.sh $1 $2 noise-floor
UserParameter=mktk.rx-rate[*],mktk.sh $1 $2 rx-rate
UserParameter=mktk.tx-rate[*],mktk.sh $1 $2 tx-rate
Так как на Mikrotik-ах один аккаунт, был написан скрипт mktk.sh (владельцем файла должен быть пользователь zabbix и лучше всего права 700 на него, т.к. там учетная запись к устройствам):
#!/bin/sh export MKTK_USER=myuser export MKTK_PASS=mypass /usr/home/null/scripts/mktk.pl $*
Все, что теперь остаётся — в Zabbix в Элементу в параметре "Ключ" вставить, к примеру, mktk.frequency[10.1.0.3,wlan1]. Дальше построить график.
P.S. Впервые попробовал git :-) Интересная штуковина, ранее только cvs пользовался, даже subversion не попробовал (я — динозавр).
UP: Для получения OID-ов можно в консоли Mikrotik-а вызвать следующее:
/interface wireless print oid
— позволяет получить oid-ы к следующим параметрам: tx-rate,rx-rate,strength, ssid, bssid, frequency, band.
/interface wireless registration-table print oid
— позволяет получить oid-ы к следующим параметрам: strength, tx-bytes, rx-bytes, tx-packets, rx-packets, tx-rate, rx-rate.
Все!
8 комментариев:
RouterOS RB750 может показывать тем-ру?? Если да то какой ОИД нужно юзать??
I would like to use your script for monitoring Mikrotik wlan stats. I have following question : Where should be the script 'mktk.sh' placed to be accesible by the Agent?
I've set DebugLevel=4, i.e. lots of information in zabbix_agentd.log, but no errors. In Zabbix frontend can be seen this: "Get value from agent failed: cannot connect to [[192.168.5.38]:10050]: [111] Connection refused". In mktk.sh is correct name and password to log to Mikrotik (tested with Telnet).
I think Agent cannot "see" and/or access the script an thus cannot import name and password from it.
any suggestion?
Thank You in advance
Mirek
Mirek, place mktk.sh on server where you have zabbix_agentd. Edit zabbix_agentd configuration file and start this daemon.
Thank you very much for the quick reply.
Actually I am facing problems with the script functionality.
The device I am testing is Mikrotik RB411 with ROS 5.20, connected to AP (thus, it is in Client mode)
(tested from CentOS 6.5)
mktk.sh configuration:
#!/bin/sh
export MKTK_USER=zabbix
export MKTK_PASS=poiutrewq7
mikrotik.pl $*
--------------------------------------
[root@localhost sbin]# mktk.sh 192.168.5.170 wlan1
command timed-out at /usr/local/sbin/mikrotik.pl line 64
[root@localhost sbin]#
--------------------------------------
Indeed, both username and password are successfully exported from mktk.sh to mikrotik.pl, script connects to Mikrotik (according to log in it: "user zabbix logged in from 192.168.5.119 via telnet"
User "zabbix" belongs to group "full", so it has full access to Mikrotik
line 64 in mikrotik.pl :--------------
$data .= $_ foreach $mktk->cmd(qq{ /interface wireless monitor $WlanInterface once });
--------------------------------------
The script "found" an interface "wlan1", but it seems that the Mikrotik did not recognize the command at line 64.
BUT, when using Telnet in Windows:
--------------------------------------
[zabbix@Mikrotik-RB411] > interface wireless monitor wlan1 once
status: connected-to-ess
band: 5ghz-a
frequency: 5680MHz
wireless-protocol: 802.11
tx-rate: 48.0Mbps
rx-rate: 54.0Mbps
ssid: some_ssid
bssid: some_MAC_address
radio-name: some_radio_name
signal-strength: -66dBm
signal-strength-ch0: -66dBm
tx-signal-strength: -67dBm
noise-floor: -99dBm
signal-to-noise: 33dB
tx-ccq: 91%
rx-ccq: 99%
p-throughput: 25845
overall-tx-ccq: 91%
authenticated-clients: 1
current-distance: 1
wds-link: no
bridge: no
nstreme: no
framing-mode: none
routeros-version: 2.9.31
last-ip: some_IP_address
802.1x-port-enabled: yes
management-protection: no
compression: no
current-tx-powers: 6Mbps:14(14/14),9Mbps:14(14/14),12Mbps:14(14/14),
18Mbps:14(14/14),24Mbps:14(14/14),36Mbps:14(14/14),
48Mbps:14(14/14),54Mbps:14(14/14)
notify-external-fdb: no
---------------------------------------
I do not know where the problem might be. It seems that the script has not put "wlan1" instead of $ WlanInterface.
But the same problem occurs even though it is put manually to the script, ie:
$ data. = $ _ Foreach $ mktk-> cmd (qq {/ interface wireless monitor wlan1 once});
It could be a problem with the installation of Perl and/or its modules, couldn't it?
I have installed all modules, mentioned in the script via CPAN:
common::sense, Net::Telnet::Cisco, Data::Dumper and JSON::XS
What do you think?
Best regards
Mirek
One more note:
exactly the same error (at Line 64) occurs also in MS Windows (ActivePerl-5.16.3.1603-mswin32-x86-296746, plus all of the above modules, downloaded and installed via ppm. So it looks like that's not a problem with Perl and the modules.
Mirek
Above problem most likely solved !
Instead of "/interface wireless monitor wlan1 once" in my case should be "/interface wireless monitor wlan1 once without-paging"
Yet verified via the following script, not in Zabbix:
----------------------
#!/usr/bin/perl
use Net::Telnet::Cisco;
my $mktk = Net::Telnet::Cisco->new(
Host => 'ip_address',
Port => 23,
Prompt => '/[\>\#] $/',
Timeout => 30);
$mktk->login('user' , 'password');
print $mktk->cmd('/interface wireless monitor wlan1 once without-paging');
--------------------
Mirek
Now I am able to create the file "192.168.5.170_mktk" in /tmp directory, containing all information on wireless stats, but only if the mktk.sh is executed manually from the shell.
No success with Agent yet (user parameters in zabbix_agentd.conf, both mktk.sh and mikrotik.pl in the directory with zabbix_agentd. Not working even with ./zabbix_get -s 192.168.5.170 -p 10050 -k "mktk.tx-ccq[192.168.5.170,wlan1]".
So I will experiment further with zabbix_get to finally create at least the file "192.168.5.170_mktk" in / temp directory.
M.
Now it works, thanks for the very useful script
Mirek
Отправить комментарий