IPLIKE

From OpenNMS

IPLIKE uses a very flexible search format, allowing you to separate the four octets (fields) of a TCP/IP address into specific searches. An asterisk (*) in place of any octet matches any value for that octet. Ranges are indicated by two numbers separated by a dash (-), and commas are used for list demarcation.

For example, the following search fields are all valid and would each create the same result set--all TCP/IP addresses from 192.168.0.0 through 192.168.255.255:

   * 192.168.*.*
   * 192.168.0-255.0-255
   * 192.168.*.0-255

You cannot mix lists and ranges within the same octet. For example, the following filter is illegal:

   * 192.168.0,1,2,4-255.*

Instead you must use two separate rules:

   * 192.168.0,1,2.*
   * 192.168.4-255.*

Here is an example of using iplike in a query's where clause -

iplike(ipaddr, '192.8.*.*')

There's a more detailed IPLIKE example for those who need it.

Contents

how iplike works

Iplike is a stored procedure which has to be installed within the postgres database. There are two different implementations of iplike: one implementation is realized with the postgres plpgsql language, the other version is a compiled C function (within a shared library) which normally should be installed into the postgres opennms db during installation. The performance of the compiled C function is much better than the performance of the plpgsql-version. Having the plpgsql version running may lead to major performance problems if you have a lot of nodes in the database and if you use a lot of IPLIKE statements in your filter rules.

You can check which version is installed in your db with

 psql -U opennms -h localhost -c '\df+ iplike' | head

The output should look like

                                                  List of functions
  Schema |  Name  | Result data type | Argument data types | Volatility |  Owner  | Language | Source code | Description 
 --------+--------+------------------+---------------------+------------+---------+----------+-------------+-------------
  public | iplike | boolean          | text, text          | volatile   | opennms | c        | iplike      | 

Check the value of the "Language" column. If it's "plpgsql", then you're using the plpgsql version of this stored procedure. This may happen due to wrong installation precedence, version problems or if you have dropped the database to start all over. Look for a script named install_iplike.sh, it should reside in /usr/sbin or /usr/local/sbin and start the script:

 /usr/local/sbin/install_iplike.sh

Check again which version is installed. If you get the following error during install_iplike.sh

 ERROR:  incompatible library "/usr/local/lib/iplike.so": missing magic block
 HINT:  Extension libraries are required to use the PG_MODULE_MAGIC macro.

then your version of the compiled C function is not compatible with your postgres version. You probably have to get the source code for iplike from the repository and compile it yourself.

compiling iplike

download package for iplike & unzip / untar it in your installation directory

cd to your installation directory
./configure
make
make install

look within the last lines of messages from make install where the script install_iplike.sh went to

start postgres database
run install_iplike.sh 

check if iplike is installed into postgres-db like described above

If you get following error message from the ./configure process

configure: error: PostgreSQL is required

than you have to install the postgres-devel-... package befor configuring

compiling iplike on FreeBSD

IPLIKE is available via ports at databases/iplike
If you haven't done so already, update your ports &

  1. cd /usr/ports/databases/iplike
  2. make install clean

IPLIKE Binaries

IPLIKE binaries are available for most platforms now, as part of that platform's packaging system (Fink on Mac OSX, Debian or RPM packages on Linux, etc.)

IPLIKE on Windows

This will walk you through setting up IPLIKE on Windows.

  1. Download the IPLIKE DLL for your PostgreSQL version from SVN.
  2. Copy the file to your PostgreSQL lib directory. (ie, C:\Program Files\PostgreSQL\lib)
  3. Start pgAdmin and connect to your database.
  4. In the menu, click Tools -> Query Tool.
  5. Put the following line in the top window (replace 'IPLIKE-8.3.dll' with the relevant DLL name): CREATE OR REPLACE FUNCTION IPLIKE(text,text) RETURNS bool AS 'IPLIKE-8.3.dll' LANGUAGE 'c' WITH(isttrict)
  6. In the menu, click Query -> Execute.

Version History/Availability

Personal tools
DevJam 2008 Sponsors
DevJam 2008 Sponsor: Google
DevJam 2008 Sponsor: Netregistry
DevJam 2008 Sponsor: Papa John's
NewEdge Networks
OpenNMS takes home the gold award!
Join the Free Software Foundation
Support This Project Commercial OpenNMS Support OpenNMS Italia Get OpenNMS at SourceForge.net. Fast, secure and Free Open Source software downloads Our Network Simulator Our Java Profiler