Creating groups of devices with Regular Expressions in ITNM
MattDuggan 270001YJP0 Visits (2962)
IBM Tivoli Network Manager (ITNM) provides a flexible network discovery engine that allows users to customize what's discovered from the network and how it's modeled in the Network, Connectivity & Inventory Model (NCIM) topology database. This short blog entry will discuss how to create groups of devices based on regular expression matches against device names using ITNM's disc
So, lets jump right in - check out the comments in the stitcher for a description of what does what. The aim here is to either create a group of devices with names that match the following regular expression (names such as A-IBM67 or B-IB
The neat thing about using groups in ITNM is that they end up as collections in the NCIM topology database and so you can use them for visualization, monitoring policy scopes, reports, your own scripts and event correlation via Service Affecting Events (SAE) to inform users of problems with devices named A-IBM67, B-IBN89 and so on.
Create a file called $NCH
// regular expression match against the discovered device name
// This is kicked off by another stitcher or on-demand via ncp_oql
// Declare stitcher variables.
int isRediscovery = 0;
isRediscovery = eval(int, '$ARG_1');
// regular expression to find devices with the required name
// and drives creation of the groups.
text regularExpression = "^[a
// variables used during the processing. The collectionEntityOID is used
// by ncp_model and ModelNcimDb.cfg to map the OQL record to an NCIM collection
// entity and the coll
int regexpMatch = 0; // whether or not we've matched regularExpression
text entityName = NULL; // name of the device in the main loop
text collectionName = "Devices Named [a-z
text collectionEntityOID = "ITNM_SERVICE"; // collection EntityOID
// this controls how our collections are named. By default, we name them using
// the collectionName defined above but setting this variable to 1 will create
// multiple groups named after the group of the regexp match, i.e.
// Devices Named A-IBM55, Devices Named B-IBN67 and so on
text groupOne = NULL; // the first regexp group
// a list of devices we'll process
RecordList deviceName = NULL;
// we need an OQL query to populate the record list but we
// change the query based on whether we're doing a rediscovery
// or not for efficiency reasons.
if(isRediscovery == 0)
// all devices
deviceName = RetrieveOQL
WHERE EntityType = 1;"
// only newly (re)discovered devices
deviceName = RetrieveOQL
WHERE EntityType = 1;
// iterate through each device the OQL query has found and
// add it to our set if required.
// retrieve the EntityName from the record and assign it to entityName
entityName = eval
// evaluate whether or not the entityName satisfies our regexp
regexpMatch = MatchPattern( entityName, regularExpression );
// we've got a match so lets create the collection record
if( regexpMatch == 1 )
// if we're doing per-group collections, rejig the entityName
groupOne = eval
if(groupOne != NULL)
collectionName = eval(text, 'CAT(`Devices Named [a-z
groupOne = NULL;
// we have to add this device to the set but make sure
// the set exists whether we need to firstly create it or not.
WHERE EntityName = eval
// we haven't got the set record created so lets create it now
"INSERT INTO scra
m_ServiceName = eval(text, '$co
m_ServiceType = 'Managed',
m_CustomerName = 'Your Customer Name',
m_Members = 
// we'll have the collection record now and so add the current device to the
// set if it doesn't already exist in the set, m_Members is an array.
WHERE EntityName = eval(text, '$collectionName')
AND eval(text, 'entityName') NOT IN ( Extr
// reset our regexp match/did not match flag to zero
regexpMatch = 0;
entityName = NULL;