Page 1 of 1

Zabbix Template

Posted: Mon Nov 25, 2013 5:10 pm
by troy
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.

Re: Zabbix Template

Posted: Tue Apr 08, 2014 10:44 pm
by vddsd

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!

Re: Zabbix Template

Posted: Fri Apr 11, 2014 4:40 pm
by terolando
Hello, I am new to zabbix.

I wonder where I include This PHP script

thank you

Re: Zabbix Template

Posted: Fri Apr 11, 2014 5:04 pm
by terolando
Hello, I am new to zabbix.

I wonder where I include This PHP script

thank you

Re: Zabbix Template

Posted: Thu May 22, 2014 1:44 am
by troy
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 

Re: Zabbix Template

Posted: Thu May 22, 2014 11:43 am
by levak
YOu have the option of having trigger dependencies... I'm no sure if that solves your problem. ... pendencies

Re: Zabbix Template

Posted: Thu May 22, 2014 2:56 pm
by LuizMeier
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?

Re: Zabbix Template

Posted: Sat May 31, 2014 5:51 am
by troy
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.

Re: Zabbix Template

Posted: Sun Jun 01, 2014 12:18 pm
by whmcr
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!

Re: Zabbix Template

Posted: Wed Jun 18, 2014 6:46 am
by vovannovig
Please lay out the latest and correct version - Zabbix Template

Re: Zabbix Template

Posted: Fri Nov 14, 2014 5:56 pm
by masierovinicius
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.

Re: Zabbix Template

Posted: Thu Nov 20, 2014 12:55 pm
by troy

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 noise
This should give you an idea of what's going on.

Re: Zabbix Template

Posted: Sun Jan 04, 2015 2:05 pm
by mmv
There no point on which of API lib used as mtapi.php
I found correct one

Re: Zabbix Template

Posted: Thu Feb 05, 2015 1:02 pm
by masierovinicius
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!!

Re: Zabbix Template

Posted: Mon Feb 09, 2015 5:40 pm
by masierovinicius

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.|

Re: Zabbix Template

Posted: Wed Feb 11, 2015 5:18 pm
by troy
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:
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.
<?php printf("%d\n",10); ?>

Re: Zabbix Template

Posted: Mon Feb 23, 2015 9:39 pm
by masierovinicius
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
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.


Re: Zabbix Template

Posted: Tue Feb 24, 2015 2:04 pm
by masierovinicius
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