IPLIKE

From OpenNMS
Jump to: navigation, search

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.

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 postgres -h localhost -d opennms -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

If you're installing on Postgres 9.0, the directory may have moved. On CentOS 5.5 you will have to modify the configure line to look like this.

./configure --with-pgsql=/usr/pgsql-9.0/bin/pg_config

If this does not work, you will have to find pg_config and edit the command above accordingly.

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

To build an RPM for install, you can run rpmbuild to build the package. Make sure pg_config is in your path, or the configure step will fail. Postgresql.org's rpms for 9.1 install under /usr/pgsql-9.1, so as an example:

PATH=/usr/pgsql-9.1/bin:$PATH
rpmbuild -tb iplike-2.0.2.tar.gz

If you get following error message from the install_iplike.sh process

ERROR:  cannot change name of input parameter "i_ipaddress"
HINT:  Use DROP FUNCTION first.

than you have to log in into the db and drop the function like:

/usr/local/pgsql/bin/psql -U opennms opennms
drop function if exists iplike(text,text);
\q

If you get following error message from the install_iplike.sh process

ERROR:  could not load library "/usr/local/pgsql/lib/iplike.so": libpq.so.5

than you have to add a path for the directory of the postgres runtime libraries to the loader like:

Create

/etc/ld.so.conf.d/postgresql.conf 

and add a line like

/usr/local/pgsql/lib

after this, you have to activate the entry running

 ldconfig

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.