Wednesday, March 3, 2021

Deleting newlines or merging two lines in a file using Notepad++

It took me longer than it should have to find this link explaining how to delete a newline or merge two lines in Notepad++:

https://stackoverflow.com/questions/11084086/notepad-merge-2-lines-into-1-line

Here's the text from the answer in case the above link disappears at some point:

Use the extended replace functionality and replace "\r\nname" with " name"

Substitute appropriate line ending characters for \r\n depending on the file.

If it is from windows, use \r\n

If it is from unix, use \n

If it is from mac, use \r

Basically, you need to find and replace the appropriate characters, and it works just like one would expect. Finding the complete set of correct characters was the key for me. Specifically, I wasn't finding "\r\n" (CRLF, the Windows newline characters). Using the above, I was able to successfully delete some spurious newlines in my data.

Monday, February 22, 2021

A new book on ServiceNow Event Management is available!

I just published my first book, Migrating to ServiceNow Event Management. In it, I provide tips and recommendations for migrating from an existing event management system to ServiceNow ITOM Event Management. The book provides details on some of the differences that exist between ServiceNow and event management systems that are not integrated with a CMDB. A large part of the book is devoted to the organizational information you need to capture to ensure a successful migration. 

It's available on Amazon in paperback or on Kindle.

https://www.amazon.com/gp/product/B08X31Y1B8



Tuesday, January 26, 2021

Call PowerShell script from batch file using a pseudo here file

 If you made it through the title of this post, you're in the right place. Due to security restrictions on a Windows 10 machine I was using, I needed to run a group of PowerShell commands in a single command from a batch file, and I found the solution here:

https://dmitrysotnikov.wordpress.com/2008/06/27/powershell-script-in-a-bat-file/

Basically, you enclose the whole set of commands in curly braces, encode those to a Base64 string, then pass that encoded string to the PowerShell command with the -EncodedCommand parameter. This encoded string is the "pseudo here file" mentioned in the title.

I needed the same code run every time, so the manual step of copy-and-pasting the encoded string wasn't a problem for me. If you need to programattically modify the code that needs to run, you're on your own. 

Tuesday, December 29, 2020

ServiceNow Event Rules: No support for If..Then..Else in regex

The Transform and Compose Alert Output section of an Event Rule in ServiceNow allows you to use regular expressions and grouping to parse data in incoming events. Almost full regular expression support is provided, but I wanted to point out one feature that's definitely not supported as of the Paris release: if..then..else conditionals. Here's a great description of this feature from regularexpressions.info. Basically, the format of this conditional is:

(?(condition)(then)|(else))

It's somewhat esoteric, but it can be useful in cases where you have two different string formats that you want to parse in a single event rule. I just tested this thoroughly on my dev instance, and it absolutely is not supported. While you can save the event rule with this syntax, you'll eventually see an error stating:

Invalid Regular Expression Field

I believe this is due to the fact that the regular expression engine does not support "lookbehind" (limitation documented here). In any case, it's not supported. I just wanted to document my findings here to save others a little headache.

Update 1/3/2021

The official name for this is Conditional Lookahead. You can play around with it at http://regex101.com if you're interested. 

And to make sure I was doing it correctly, I also tried this syntax in the Event Rule transform:

(?(?=my_pattern)(\d+)|(\w+))

This works in regex101, but gives the Invalid Regular Expression Field in the ServiceNow interface.

Friday, August 14, 2020

ServiceNow ITOM Health - Using a complex algorithm to bind an Alert to a CI

 By default with ServiceNow ITOM Health Event Management, an Alert is bound to a CI following this flowchart:

In 95-99% of implementations, you should work to configure components appropriately to leverage the above flow. 

However, there are some number of unique cases where you need to do something extremely specific that falls outside of the above decision-making process. For those cases, you will want to modify one or more of the Advanced Scripts under Event Management->Settings in the navigator. Specifically, to change the bound CI, you would modify the EvtMgmtCustom_PostBind_Create script to suit your needs. In this script, you can do anything you want to the alert GlideRecord before it's actually written to the database. 

Read the warnings in the script definition to realize that you do NOT want to modify this script unless you know what you're doing and have some very efficient code to run. But for those few cases where you need to set the bound CI according to some esoteric algorithm, this script is where it can be done.

Thursday, July 2, 2020

How to get live metrics for CPU, Memory,Disk etc by running db2 queries in the tdw server.

I just received this question today from an ITM user and thought it would be best to answer it here.

First, The "Getting Started with IBM Tivoli Monitoring on Distributed Environments" PDF contains great information on ITM 6.1, and it is applicable to all of the 6.x versions:

http://www.redbooks.ibm.com/redbooks/pdfs/sg247143.pdf

Chapter 4 specifically goes over the Tivoli Data Warehouse, including the DB2 table and column names. Specifically, look at section 4.2.4 for descriptions of the different table names.

The tricky part in DB2 is that the table and column names are all case sensitive, which means you need to enclose the table name inside double-quotes in your sql statement. For example, you would use this SQL statement to get percent processor time for all processes for all servers:

select "%_Processor_Time","Process_Name" from "NT_Process"

If you want to see data that hasn't yet made it to the TDW, then you need to use the krarloff command described here:


Friday, June 12, 2020

Exception handling in Maximo automation scripts with try except

For the longest time, I thought that try/except blocks didn't work in automation scripts. A colleague asked me about them yesterday, so I figured I would try it out again, and found that they work. It's really just like normal Python exception handling. Here's a script I used to test it, with an Object Launch Point on Save for the SR object:

from psdi.server import MXServer
import sys

try:
  mbo.getMboValue("FOOBAR")
except:
  print "an error was encountered"
  e = sys.exc_info()[0]
  print(e)

The expected behavior is that a message will be written to the log file, but that an SR will be created, and that's exactly the behavior I observed. Here's what was in the log file:

[6/12/20 9:25:50:961 EDT] 000021c4 SystemOut     O 12 Jun 2020 09:25:50:961 [DEBUG] [MAXIMO] [] an error was encountered
<type 'psdi.util.MXApplicationException'>

Happy scripting!