Community discussions

MikroTik App
 
troy
Member
Member
Topic Author
Posts: 320
Joined: Thu Jun 30, 2005 6:47 pm

Zabbix Template

Mon Nov 25, 2013 5:10 pm

I had heard about zabbix quite some time ago, but never seemed to find the time to tackle the learning curve. This past weekend, I decided it was time, so I did and I'd like to share the results with you.

This template is incomplete at best, but so far, it's doing what I need it to do. I'm open to requests, suggestions, and patches to improve it.

This template uses 3 Macros:
{$SNMP_COMMUNITY} global macro - can be overridden at the template or host level
{$USER} - user macro in the template - can be overridden at the host level
{$PASS} - user macro in the template - can be overridden at the host level

The template uses SNMP where possible, but since MT's implementation of SNMP is woefully lacking, there are some values being pulled using the API and a PHP script. Also, SNMP interface stats are pulled using ifDescr and the default interface names. If you rename your interfaces, you'll need to rename them in the template (or hosts) as well.

The PHP script does make use of one function (array_column) that was introduced in PHP 5.5. if you have an earlier version of PHP, you'll need to upgrade or write your own function.

I freely admit that my PHP script is quick and dirty, but it does what I need. If someone wants to help improve and extend the script, I'm happy for the help. At a minimum, it would probably be good to add some code to pull wireless stats from each wlan interface individually for those who need it.

Pull the mt api class from the wiki if you need it.
You do not have the required permissions to view the files attached to this post.
 
vddsd
just joined
Posts: 16
Joined: Wed Jul 04, 2012 1:12 am
Location: NB, Canada

Re: Zabbix Template

Tue Apr 08, 2014 10:44 pm

Hi,

thanks for sharing your work!

I tried to implement your template in our environment but I'm having trouble making your script work. I copied the mtstatus.php AND the mtapi.php files in our externalscripts directory, copied the Mikrotik MIB file in the proper directory and imported the Zabbix template.

I ensure the Macros were properly set and I linked the template to one of our Mikrotik devices. Zabbix is gathering SNMP data but no "external check" data.

Perhaps I didn't copy the files in the proper spot. Are you able to confirm where I should copy the .php files? Any way to manually test the scripts to see if they work in our environment?

Thanks again!
 
terolando
just joined
Posts: 2
Joined: Sat Dec 07, 2013 3:31 pm

Re: Zabbix Template

Fri Apr 11, 2014 4:40 pm

Hello, I am new to zabbix.

I wonder where I include This PHP script

thank you
 
terolando
just joined
Posts: 2
Joined: Sat Dec 07, 2013 3:31 pm

Re: Zabbix Template

Fri Apr 11, 2014 5:04 pm

Hello, I am new to zabbix.

I wonder where I include This PHP script

thank you
 
troy
Member
Member
Topic Author
Posts: 320
Joined: Thu Jun 30, 2005 6:47 pm

Re: Zabbix Template

Thu May 22, 2014 1:44 am

Sorry for the very late reply... Zabbix has landed on my back burner. It's awesome at what it does, but there are 2 serious limitations that I can't live with right now. The Android apps all suck and Zabbix doesn't currently support host dependencies (if a device goes down and takes 20 more with it, I don't want the flood of alerts).

I put the script and mtapi.php in the zabbix externalscripts folder and made the script executable to call /usr/bin/php. If your stuff is installed to different directories, then adjust accordingly.

bash code

troy@zabbix:~$ ls -l /usr/lib/zabbix/externalscripts/mtStatus 
-rwxr-xr-x 1 root root 1144 Nov 26 17:14 /usr/lib/zabbix/externalscripts/mtStatus
troy@zabbix:~$ head -1 /usr/lib/zabbix/externalscripts/mtStatus 
#!/usr/bin/php
 
levak
Frequent Visitor
Frequent Visitor
Posts: 76
Joined: Thu Feb 21, 2013 8:47 pm
Contact:

Re: Zabbix Template

Thu May 22, 2014 11:43 am

YOu have the option of having trigger dependencies... I'm no sure if that solves your problem.

https://www.zabbix.com/documentation/1. ... pendencies
 
LuizMeier
Member Candidate
Member Candidate
Posts: 104
Joined: Tue Sep 25, 2012 11:57 pm
Location: Curitiba, PR - Brasil

Re: Zabbix Template

Thu May 22, 2014 2:56 pm

There are many Zabbix applets for Android. I can't believe that at least one is not good for you.

About the script directory, if you don't know where it is, you always have the choice of be using your script as UserParameter.


Doesn't that mtapi.php required on the same directory?
 
troy
Member
Member
Topic Author
Posts: 320
Joined: Thu Jun 30, 2005 6:47 pm

Re: Zabbix Template

Sat May 31, 2014 5:51 am

Yeah, that api file needs to be in the same directory for the script I threw together. You can put it anywhere you want if you edit the script... php includes/requires are pretty easy to change.

As for the dependency thing, I looked at it, and it's overly complex. A host dependency needs to be a simple parent-child relationship. If the parent is down, suspend all operations on the child. Simple. It amazes me that Zabbix missed this. Even our beloved 'The Dude' has this feature, and it's been an unfinished beta for years now.

On the android app, I need something with a very simple interface. Currently, I use aNag against multiple Nagios servers. It works perfectly. It's easily configured to alert me when there's a problem and to filter out unreachable hosts.

Sure, there are plenty of apps, and perhaps one of them will do what I need. Unfortunately, most of them won't run unless you're running the latest bleeding edge version of the OS. Newsflash... there are a TON of android devices that will never be updated past 2.x. If developers want people to use their apps, they need to make them available. It's not worth it to me to spend hundreds on a new phone or sign yet another contract with a phone company that's already raping it's customers on the monthly rates. Not to mention that none of the carriers even offer a decent phone with a full keyboard anymore. SSH is bad enough on a 4" screen. I don't need half of it taken up by a semi-functional on-screen keyboard.

Don't get me wrong, I REALLY like what Zabbix does. My problem is what it doesn't do and doesn't have yet.
 
whmcr
just joined
Posts: 2
Joined: Sun Jun 01, 2014 12:09 pm

Re: Zabbix Template

Sun Jun 01, 2014 12:18 pm

So I've done something similar to this for Firewall Rules and just wanted to share a couple of things.

You've got a couple of options here on how to run this, the method mentioned using external check on the zabbix server or proxy is going to be fine, to a point. The more systems you start to monitor, the more bogged down the zabbix processes are going to be. You're going to want to try and limit the number of external checks running at any time. At $work we're using external checks for LLD for other devices (f5 load balancers for example). On moderate sized proxies (2vCPU / 8GB ram / Postgresql for proxy db, 1:1 pCPU:vCPU ratio) we're doing ~500-600 concurrent external checks without issue, but when hitting 1000 we start to have issues with the number of processes being forked at any one time. The key thing is to make sure you keep the processing time of each external check down to a minimum.

The other way, is actually a way around this issue. If you deploy a Zabbix agent on a host, and use the UserParamaters on the agent to collect the items. This means that you've got a linearly scaleable system. You could, potentially, even deploy the agent on a meta router. I've not done this my self, but its something that could be done.


In terms of collection of data, I'm a big fan of LLD. I'll post a bit later the (horrid) script that i've done to collect Firewall rule counts which uses LLD. This means that you don't need to update zabbix to take into account new rules that have been added, at the next LLD run, it will automagically add the new rules based on your item prototypes. Its rather spffy indeed!
 
vovannovig
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Tue Feb 11, 2014 10:55 pm

Re: Zabbix Template

Wed Jun 18, 2014 6:46 am

Please lay out the latest and correct version - Zabbix Template
 
masierovinicius
just joined
Posts: 6
Joined: Fri Nov 14, 2014 5:46 pm

Re: Zabbix Template

Fri Nov 14, 2014 5:56 pm

Hi guys!

I downloaded and installed the template and i put the script (mtStatus) and mtapi.php in "externalscripts" folder, but this dont work.

i follow all your hints above and doesn't work.

zabbix shows me the error: receveived value [] is not suitable for value type (numeric (float)).

i belive in a empty return.

someone can help me?

Ps: sorry for my bad english.
 
troy
Member
Member
Topic Author
Posts: 320
Joined: Thu Jun 30, 2005 6:47 pm

Re: Zabbix Template

Thu Nov 20, 2014 12:55 pm

Masi,

I kinda gave up on Zabbix for the time being. In fact, I've not looked at it for quite some time.

However, the error you report sounds like a problem with the mtStatus script, which has absolutely no error checking and only a very minimum of data manipulation. It's also only used for getting some additional information for wireless devices. Try running it from the command line:
./mtStatus admin P@ssW0rd 192.168.12.34 noise
This should give you an idea of what's going on.
 
User avatar
mmv
Trainer
Trainer
Posts: 67
Joined: Wed Feb 24, 2010 5:03 pm
Location: Moscow, Russia
Contact:

Re: Zabbix Template

Sun Jan 04, 2015 2:05 pm

There no point on which of API lib used as mtapi.php
I found correct one http://wiki.mikrotik.com/wiki/API_PHP_class
 
masierovinicius
just joined
Posts: 6
Joined: Fri Nov 14, 2014 5:46 pm

Re: Zabbix Template

Thu Feb 05, 2015 1:02 pm

Thanks guys!!

I tested the mtStatus and include mtapi from above link, in version 1.6.

i belive in a error on my old mtapi.php.

its full funcional now.

Thanks for your help!!
 
masierovinicius
just joined
Posts: 6
Joined: Fri Nov 14, 2014 5:46 pm

Re: Zabbix Template

Mon Feb 09, 2015 5:40 pm

Hello!

There more one issue in my experience with mtStatus:

The output is showing two newlines characters before real number.

Is there a way to eliminate this two characters (0a)?

Ex: The output with hexdump -C:
00000000  0a 0a 31 0a                                       |..1.|
00000004
 
troy
Member
Member
Topic Author
Posts: 320
Joined: Thu Jun 30, 2005 6:47 pm

Re: Zabbix Template

Wed Feb 11, 2015 5:18 pm

Definately not using this myself anymore, but I'm not sure where the extra lines could be coming from. The only thing the script should be spitting out is an integer value:
printf("%d\n",$return);
The newlines are probably coming from PHP and how it's handling the script, or possibly due to some extra/empty lines somewhere in the file, but outside the script itself.

Try this script to check. Make sure the file you create has just these 2 lines and nothing empty. Also try inserting a blank line or two between these two lines.
#!/usr/bin/php
<?php printf("%d\n",10); ?>
 
masierovinicius
just joined
Posts: 6
Joined: Fri Nov 14, 2014 5:46 pm

Re: Zabbix Template

Mon Feb 23, 2015 9:39 pm

Thanks for your reply Troy!

I tested with your test script and i got an output without newlines.

Testing in mtStatus i discovered which when i insert blank lines between
#!/usr/bin/php
and
<?php
the script inserts newlines in output.

The problems is: When i erase all blank lines in the test script, the output dont shows newlines. But in mtStatus and other script with API resource, still has one newline character before the true result.

Ideas?
 
masierovinicius
just joined
Posts: 6
Joined: Fri Nov 14, 2014 5:46 pm

Re: Zabbix Template

Tue Feb 24, 2015 2:04 pm

Hello Everybody!

I did it!

The problem was blank lines in mtapi.php after "?>".

I removed it and the newline character disapeared.

Zabbix recognize the outputs without problems.

Thanks for your help! :D