2010/06/07

Мониторинг Mikrotik с помощью Perl и Zabbix

Γεια σας, κύριοι συνάδελφοι!

Появилась задача следить за кучей Микротиков в 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 на него, т.к. там учетная запись к устройствам):

  1. #!/bin/sh
  2. export MKTK_USER=myuser
  3. export MKTK_PASS=mypass
  4. /usr/home/null/scripts/mktk.pl $*
  5.  

Все, что теперь остаётся — в 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

dynax60 комментирует...

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

Ярлыки

perl (30) infosec (26) links (21) freebsd (16) url (16) zabbix (14) ipv6 (13) linux (12) asterisk (10) mojo (10) monitoring (10) snmp (10) fun (8) openssl (7) security (7) bgbilling (6) cisco (6) mysql (6) ubuntu (6) blogs (5) dlink (5) kannel (5) crypto (4) exploits (4) ipv4 (4) java (4) js (4) law (4) microsoft (4) mikrotik (4) mojolicious (4) oracle (4) performance (4) postfix (4) radio (4) ssl (4) tools (4) utf-8 (4) vmware (4) windows (4) android (3) apache (3) books (3) debug (3) dns (3) google (3) hp (3) json (3) latex (3) openbsd (3) python (3) quotes (3) rhel (3) ripe ncc (3) syslog (3) ubnt (3) vim (3) vm (3) agi (2) ansible (2) atlassian (2) backup (2) bgp (2) bind (2) centos (2) console (2) cpan (2) cpanmin (2) css (2) ctf (2) docker (2) dwpd (2) edge-core (2) editors (2) elasticsearch (2) endurance (2) git (2) gns3 (2) graphite (2) hack (2) hdd (2) hyper-v (2) isp (2) mac (2) management (2) mibs (2) movie (2) msa (2) ntp (2) pentest (2) puppet (2) qa tests (2) reverse engeenering (2) shell (2) smpp (2) social engineering (2) spf (2) ssd (2) statistic (2) storage (2) switches (2) tbw (2) tcp/ip (2) tex (2) usb (2) websec (2) wsl (2) xsrf (2) yandex (2) ПДн (2) электронное правительство (2) #snmp #cisco (1) ESNI (1) Xorg (1) amavis (1) amazon s3 (1) analyze (1) anonymous (1) applications (1) as (1) ascii (1) autofs (1) balancer (1) bandwidth (1) bem (1) bl (1) brendan gregg (1) cache (1) certificate (1) chef (1) chief (1) cluster (1) cnupm (1) cnupmsave (1) confluence (1) cpu (1) cvs (1) dbi (1) ddos (1) deploy (1) devices (1) dhcp (1) dht (1) diet (1) disk (1) diskarray (1) dummynet (1) dynax60 (1) epub (1) equipment (1) esx (1) esxi (1) fax (1) firefox (1) firmware (1) fitness (1) form (1) fs (1) fsb (1) ftp (1) go (1) golf (1) gprs (1) graphics (1) gsm (1) honeypot (1) hpe (1) hpe ilo manager (1) html (1) img (1) iops (1) ios (1) ipn (1) ipsec (1) iptv (1) iso (1) itil (1) itsm (1) jabber (1) jira (1) joke (1) jsonp (1) kafka (1) kubernetes (1) law. simcards (1) lens (1) logstash (1) mem (1) memory (1) metasploit (1) microscope (1) mindmap (1) mobile (1) modem (1) mp3 (1) music (1) nano (1) nas (1) netbox (1) netdev (1) netmiko (1) noc (1) nvme (1) ocfs2 (1) ocs2 (1) openfire (1) openvpn (1) oscm (1) ospf (1) otrs (1) packet filter (1) packet tracer (1) parsing (1) pass-the-hash (1) pf (1) pgu.mos.ru (1) phd (1) php (1) poe (1) ports (1) postfixadmin (1) ppp (1) presentation (1) profiler (1) protobuf (1) quickspecs (1) rabbitmq (1) radmin (1) raid (1) repo (1) rest (1) riemann (1) rkn (1) rrd (1) rs-232 (1) rss (1) rtp (1) ruby (1) runet (1) scanners (1) serialization (1) sip (1) skype (1) sms (1) snmptranslate (1) soap (1) spam (1) spamcop (1) specs (1) sql (1) ssrf (1) standarts (1) strategy (1) sudoers (1) svn (1) syslog-ng (1) tde200 (1) tftp (1) tls (1) tomcat (1) tuning (1) uce (1) underground (1) ups (1) video (1) voip (1) vpn (1) wds (1) web (1) websockets (1) wifi (1) wireless (1) x-plane (1) xml (1) xss (1) zabbix snmp (1) верстка (1) гибдд (1) гипервизоры (1) здоровье (1) панчеры (1)