Exclude CI's based on Host name

Voona Rohila
Kilo Patron
Kilo Patron

Hi

Can anyone help me with discovery related to exclude CI's based on host name i.e starting with d2,D2 not with IPAddress

I Tried with 2 methods

1) I tried modifying DiscoveryJSONIDSensor and DiscoveryIDSensor  script includes by adding the below script at Line89

var regexp = new RegExp('^[dD][2]'); //hostnames ending in p01 or P2 or similar
        var host_name = this.ciData.data.host_name;
      
        if (!host_name)
            host_name = this.ciData.data.name;
		var sub = host_name.substring(0,2);
       if (sub=='d2' || sub=='D2'){
       this.explore = false;

       this.setTriggerProbes(false);         

       logger.info('Non-prod machine: '+ host_name +'. Not exploring device', this.type, this.getEccQueueId());

       return false;

} else {

       logger.info('Production Machine: '+ host_name +'. Continue to explore device', this.type, this.getEccQueueId());

}

2)  I tried changing Classifier by adding Classification Criteria.

Both the cases did not worked 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
1 ACCEPTED SOLUTION

 

Hi Rohila,

Apologies, looks like I have some errors in my notes on this. You could try the following:

hostname instead of host_name with Windows. i.e. hostname does not start with d2:

find_real_file.png

cidata.host_name does not start with d2:

find_real_file.png

If you still have a problem, post a screenshot of the classifier and I will have a look.

I would also test this thoroughly before doing deciding to implement this in a production envrionment.

Regards,

Dave

 

View solution in original post

7 REPLIES 7

Dave Ainsworth
ServiceNow Employee
ServiceNow Employee

Hi Rohila,

I would not modify those script includes because the files will be skipped on future upgrades of ServiceNow and could cause problems for Discovery if changes are not merged back in.
 
Instead I would attempt the second method you suggested. The following should work (I have used Linux with a hostname ‘centos2’ as an example but should work with Windows and any other OS):
 
Add classification criteria as follows:
 
Go to the appropriate classifier and add the following classification criteria:
Name: host_name
Operator: does not start with
Value: d2
 
On the classification form, change Match criteria to All (default is Any but there is now more than one classification criteria and they all need to match).
Mine looks like the following:
 
find_real_file.png
 
 
When finding a server starting with the value, classification will fail. For example, when I discover, I get the 'Active, could not classifiy' with the following in the logs:
 
find_real_file.png
 
The problem with adding criteria such as this is that there are often some exceptions. So for example, there might be some servers/workstations that begin with D2 that the customer does want to discover.
 
Also, preventing discovery in this way can cause confusion as to what are genuine unclassified CIs (i.e. CIs that you do want to discover but some classification criteria might need tweaking) and CIs that you want to prevent discovering.
 
Regards,

Dave

Hi Dave

I tried the solution you gave which is not working for windows classifers and also all the linux devices are not classifying.

 

find_real_file.png

 

I also tried using regular expressions in classification criteria but it did not worked 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

 

Hi Rohila,

Apologies, looks like I have some errors in my notes on this. You could try the following:

hostname instead of host_name with Windows. i.e. hostname does not start with d2:

find_real_file.png

cidata.host_name does not start with d2:

find_real_file.png

If you still have a problem, post a screenshot of the classifier and I will have a look.

I would also test this thoroughly before doing deciding to implement this in a production envrionment.

Regards,

Dave

 

Hi Dave,

 

Thank you for your quick response. Provided solutions are working for linux and windows. Please let us know whether we can implement this on PROD as a best practice note.

 

I have another requirement as well on the same issue.  We are blocking linux and windows of traditional discovery using classification criteria. How we can block the same if we are getting information from VCenter servers(VM Instances).

 

Shall i create a new thread for the same or can you help me out regarding this as well, which adds lot of help for us.

 

Regards,

 

Rohila


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP