Filtering using macros and regexp in Zabbix

This is a follow up on my previous blog post about JBoss monitoring and Zabbix. In that post we’re using the queryJBoss.pl script to query JBoss for message queues en later on connection pools.

Problems, problems…

One of the problems you encounter when you query jboss.jca for the connection pools, you potentially get more information from the script than you are interested in.

For example, running the queryJBoss script to get your connection pools you get:

Run:

# /opt/zabbix/queryJBoss.pl jboss.jca POOL

Result:

{
“data”:[

{
“{#POOL_JNDI}”:”jboss.jca:service=LocalTxCM,name=DefaultDS”,
“{#POOL_SERVICE}”:”LocalTxCM”,
“{#POOL_NAME}”:”DefaultDS”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=ManagedConnectionPool,name=JmsXA”,
“{#POOL_SERVICE}”:”ManagedConnectionPool”,
“{#POOL_NAME}”:”JmsXA”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=RARDeployment,name=’jms-ra.rar'”,
“{#POOL_SERVICE}”:”RARDeployment”,
“{#POOL_NAME}”:”‘jms-ra.rar'”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=ManagedConnectionPool,name=DefaultDS”,
“{#POOL_SERVICE}”:”ManagedConnectionPool”,
“{#POOL_NAME}”:”DefaultDS”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=ManagedConnectionFactory,name=JmsXA”,
“{#POOL_SERVICE}”:”ManagedConnectionFactory”,
“{#POOL_NAME}”:”JmsXA”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=ConnectionFactoryBinding,name=JmsXA”,
“{#POOL_SERVICE}”:”ConnectionFactoryBinding”,
“{#POOL_NAME}”:”JmsXA”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=RARDeployment,name=’jboss-xa-jdbc.rar'”,
“{#POOL_SERVICE}”:”RARDeployment”,
“{#POOL_NAME}”:”‘jboss-xa-jdbc.rar'”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=TxCM,name=JmsXA”,
“{#POOL_SERVICE}”:”TxCM”,
“{#POOL_NAME}”:”JmsXA”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=DataSourceBinding,name=DefaultDS”,
“{#POOL_SERVICE}”:”DataSourceBinding”,
“{#POOL_NAME}”:”DefaultDS”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=RARDeployment,name=’quartz-ra.rar'”,
“{#POOL_SERVICE}”:”RARDeployment”,
“{#POOL_NAME}”:”‘quartz-ra.rar'”
}
,
{
“{#POOL_JNDI}”:”jboss.jca:service=CachedConnectionManager”,
“{#POOL_SERVICE}”:”CachedConnectionManager”
}

]
}

The thing is, at the moment for my “connection pool” discovery rule in Zabbix I’m only interested in ManagedConnectionPool services.

I want my queryJBoss.pl to be as generic as possible, so I don’t want to limit my output on that level. Instead I want Zabbix to filter out the things I don’t need.

Solutions!

When creating a discovery rule in Zabbix, you have the option to specify a filter, using a macro and regexp:

Screen Shot 2014-01-15 at 14.49.36

Here you can control which macros will be used to create host items from. Now the macro is easy to solve. I know I only want to add the service ManagedConnectionPool as host items and the macro {#POOL_SERVICE} contains the service name. How convenient!

So for the filter macro we’re going to use {#POOL_SERVICE}.

Now I want to tell Zabbix:

” If {#POOL_SERVICE} contains “ManagedConnectionPool, use it for this discovery rule.”

Zabbix supports regular expressions, which we can use to see if {#POOL_SERVICE} contains the word “ManagadConnectionPool”.

Let’s configure a regexp to do just that. Open the regexp configuration screen by going to the tabs Administration->General.

On the right side there is a drop down menu where you can select what to configure:

Screen Shot 2014-01-15 at 15.05.22

 

Select “Regular expressions”.  There are probably some pre-configured expressions present, like the one for file system types.

Let’s create our own regexp for the ManagedConnectionPools. Click “new regular expression” and fill in:

Name: Managed connection pools for discovery

In the Expressions block, click “Add”. Here we can define to what our macro ({#POOL_SERVICE}) should match to be accepted for a host item while using discovery.

You can do a lot of great things using regexp, but for now let’s keep it simple. I only want ManagedConnectionPools to be added to my host items, so fill in:

Expression: ManagedConnectionPool
Expression Type: Result is TRUE

Click “Add”

Screen Shot 2014-01-15 at 15.16.11

There we go. Now we told Zabbix that for every entry that is tested to this regexp, we only return TRUE if the entry contains the word “ManagedConnectionPool”.

Click “Save”.

Now, when creating the discovery rule for managed connection pools you can use {#POOL_SERVICE} and the regexp we just created to test if the entry we get back from queryJBoss.pl is actually a ManagedConnectionPool:

In the “Filter” part fill in:

Macro: {#POOL_SERVICE}
Regexp: @Managed connection pools for discovery

Screen Shot 2014-01-15 at 15.20.36

Notice the “@” sign, it tells Zabbix “Managed connection pools for discovery” is a configured regular expression.

Now when the discovery rule runs, every entry the agent returns will be tested agains the filter and only the ManagedConnectionPool services will be used.

That is all there is to it, happy monitoring!

2 thoughts on “Filtering using macros and regexp in Zabbix

Leave a Reply

Your email address will not be published. Required fields are marked *