Tag Archive for 'configuration'

Playing with Oracle, ocilib and parameter bindings

Hi there,

IDOUtils queries differ quite a lot – some of the are just executed during startup, while others happen all the time. By analyzing the performance on our Oracle database with grid  it came to the top queries just like for

  • servicechecks, servicestatus
  • hostchecks, hoststatus
  • timedevents
  • programstatus

But how to improve the performance of those queries when they are called all the time?

Well, the query as is is always the same, only the values happen to change. So the basic idea is to prepare the statements with value place holders and if it comes to the query, just to bind the paramaters (values) to the prepared statement and execute that. This is a real performance boost compared to putting the query within the rdbm cache all the time.

Generally speaking the query statements are prepared after database connection and the statement handle is stored within the global dbinfo object (where the connection handler resides too).

dbinfo.oci_statement_programstatus = OCI_StatementCreate(dbinfo.oci_connection);
OCI_Prepare(dbinfo.oci_statement_programstatus, MT("MERGE INTO table USING DUAL ON (v1=:X1) WHEN MATCHED THEN UPDATE SET v2=:X2 WHEN NOT MATCHED THEN INSERT (v1, v2) VALUES (:X1, :X2)"))

When a query should be executed, all values will be binded (X1, X2) to the statement.

OCI_BindUnsignedBigInt(dbinfo.oci_statement_programstatus, MT(":X1"), (big_uint *) value1)
OCI_BindString(dbinfo.oci_statement_programstatus, MT(":X2"), (char *) value2)

Then the query gets executed.

OCI_Execute(dbinfo.oci_statement_programstatus);

Well it sounds quite simple but regarding the architecture of *DOUtils it was a hard nut to crack. The most common problem was the query buffer building – each unixtimestamp conversion is done before query building and sending the query. That does not fit for prepared statements where the whole query is pushed into the database cache.

Within the code, there is an char* array which gets the SQL-code from ndo2db_db_timet_to_sql and this is then printed to the whole statements. Not very useful since you may paste that right within each query. For the prepared statements, I’ve added all plain unixtimestamps to the data[] array and then binding the values directly.

(SELECT unixts2date(:X3) FROM DUAL)

So the bind param task has been done for the initial steps, improved delete statements and other improvements need to be implemented.

Another thing which was quite nasty is that Oracle support was dependant on libdbi, but it was not even used. So I decided to split the code completely and change configure. If you use –enable-oracle it will only require ocilib to work, it does not complain about a missing libdbi. The other way around it also works fine just like it was.

Conclusion to that – you won’t need libdbi to get Oracle support for Icinga IDOUtils – just ocilib.

Those improvements have been pushed to actual GIT master und you are very welcome to test and report bugs! =)

  • Share/Bookmark

Creating custom logos

By default your service map will show your defined services with a question mark logo, this is due to  the default logos used are unknown.gif and unknown.gd2. You can define your own custom logos thus giving a more personalised look. There have been logo packs made for use with Nagios, well theses of course will work just fine in Icinga, in this case I have made my own custom images of my router and my server.

The image types can be .jpg, .gif .png you will also need to convert the images you use to a .gd2 format as well. to do this you are going to need the pngtogd2 utility. (see notes below) I have resized these images to 40×40 pixels before conversion to .gd2 format.

pngtogd2 source_image output_imige.gd2 cs 1
  • pngtogd2 command loses transparency unless the original png file is properly formatted
  • pngtogd2 is distributed as part of the libgd-tools package in Debian and Ubuntu.
  • The image needs to be stored with an indexed rather than RGB color model. In GIMP, select Image -> Mode -> Indexed.
  • The color values for transparent pixels need to be retained.
Source : http://wiki.nagios.org/index.php/Status_Map_Images

Then create hostextinfo.cfg file in /usr/local/icinga/etc/objects and include the following…  (please note this is my configuration!)

define hostextinfo{
     host_name       IBM-eSERVER
#     notes_url       http://webserver/hostinfo.pl?host=you_can_edit_this
     icon_image      IBM-eSERVER_220.png
     icon_image_alt  IBM-eSERVER_220
     vrml_image      IBM-eSERVER_220.png
     statusmap_image IBM-eSERVER_220.gd2
#     2d_coords       100,250
#     3d_coords       100.0,50.0,75.0
     }

Your custom images need to be placed into ‘/usr/local/icinga/share/images/logos’ substitute the .png and .gd2 files to the names of the images that you will be using. Change the file ownership and permissions of your custom images and hostextinfo.cfg by using the following ‘chown dancer:icinga your_file_name’ also ‘chmod 664 your_file_name’ this matches the permissions and ownership of the files already in these directories. If you have multiple hosts then repeat the ‘define hostextinfo{…}’ that you wish to add custom logos to, if you wish to use the same logo for multiple hosts then they just need to be comma separated eg. ‘host_name     localhost1,localhost2,localhost3′

To enable your new hostextinfo.cfg you need to add the following to /usr/local/icinga/etc/icinga.cfg

# Definitions for custom logos
cfg_file=/usr/local/icinga/etc/objects/hostextinfo.cfg

Make sure that your configuration is good by running the following (as root) ‘sudo /usr/local/icinga/bin/icinga -v /usr/local/icinga/etc/icinga.cfg’ if you have no errors, then simply restart Icinga. If you do have errors then check to make sure you have defined a valid ‘host_name’ and that you have placed your custom images into /usr/local/icinga/share/images/logos

You will be rewarded with the following…

Before…

BeforeAfter…

After

These custom logos will also show up when viewing host and service details…

Services

Note: I’m using Ubuntu some commands may vary depending on distribution
  • Share/Bookmark

How I have Icinga on my home server

I’ve been using Icinga since the first release was made public back in May this year.  I first heard of the project via Twitter, and as the tweet had a URL posted I simply clicked on it and read all about what Icinga was to be about and the new direction the development team were going to take on the project as it matures. So I was keen to get my hand on the code and install it.

So after simply building and installing version 0.8.0 I had a very basic level of reporting. My home server is a work in progress, in that its really my platform for teaching myself how to both use and configure the services I have implemented. I run Postfix, Dovecot, Apache2, PHP5, MySQL (LAMP) along with SSH and vsftp. Now the default configuration provides monitoring for SSH but I was wanting to expand this to cover the FTP, SMTP & IMAP servers. So my first call for help I posted a request on the icinga-users mailing list, I received an overwhelming response to my call! (this is the icinga community at work!) Now as I have Icinga installed on that server I have only modified the localhost.cfg and appended to the end of this file the following…

# postfix vk7hse.hobby-site.org
define service{
use 			local-service
host_name 		IBM-eSERVER
service_description 	SMTP
check_command 		check_smtp
}
 
# vsftp vk7hse.hobby-site.org
define service{
use 			local-service
host_name 		IBM-eSERVER
service_description 	FTP
check_command 		check_ftp
}
 
# imap vk7hse.hobby-site.org
define service{
use 			local-service
host_name 		IBM-eSERVER
service_description 	IMAP
check_command 		check_imap

Then I added the configuration for those services… (files postfix.cfg, ftp.cfg & imap.cfg in /usr/local/icinga/etc/objects)

define host{
use 				generic-postfix
host_name 			localhost
alias 				postfix
address 			192.168.0.1
check_command 			check_smtp
max_check_attempts 		10
notification_interval 		120
notification_period 		24×7
notification_options 		d,u,r
contact_groups 			admins
}
 
define host{
use 				generic-ftp
host_name 			localhost
alias 				vsftp
address 			192.168.0.1
check_command 			check_ftp
max_check_attempts 		10
notification_interval 		120
notification_period 		24×7
notification_options 		d,u,r
contact_groups 			admins
}
 
define host{
use 				generic-imap
host_name 			localhost
alias 				imap
address 			192.168.0.1
check_command 			check_imap
max_check_attempts 		10
notification_interval 		120
notification_period 		24×7
notification_options 		d,u,r
contact_groups 			admins
}

So as you can see the formula is the same for the three services, this then results in…

services on http://www.vk7hse.hobby-site.org

So that’s how I have Icinga running here, this may not be the optimum but its working for what I need.

  • Share/Bookmark