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!

Tuesday, June 9, 2020

Windows users, set up your Print Screen key to launch the Snip and Sketch tool

After years of using different mechanisms to take screenshots or partial screenshots, I've finally recognized that the absolute best way is to configure your Print Screen key to launch the Snip and Sketch tool. It's easy to do and will make your life much easier:

https://winaero.com/blog/print-screen-screen-snipping-windows-10/

Now that it's configured, just press your Print Screen key and you can then outline a rectangular area of your screen to copy. Once selected, the image is copied to your clipboard, but the Snip application isn't launched. If you need to launch the application, you can click on the notification that was generated when you selected the area (I normally just need to paste the image into a document, so I'm very happy that the application isn't launched). That's it. It's a very small change that has made my personal workflow much more efficient.

designer/missingid error when importing application definition in ICD 7.6.1 using port forwarding

Background

I encountered a strange error with my IBM Control Desk development environment and wanted to share because I couldn't find any hits on Google.

Problem

The problem I've encountered is the following error when trying to import any application XML into ICD 7.6.1.1:


And the import fails. It does this on all Windows and Linux browsers that I tried (Chrome, IE, Firefox, Edge, new Edge, Chromium, etc.), so it doesn't appear to be a browser problem.

Workaround

I realized that my ICD VM is running on my VMWare host on a NAT network, and I've got port forwarding configured to allow me to access it from systems on my home network. So I figured I would try the same steps using a browser either running on the ICD VM itself or on another VM on the same NAT network. And that works! So the issue is something to do with my configuration of port forwarding or something else in my network AFAIK. More importantly, it's NOT a problem with ICD.

I've used my browser's Developer Tools to analyze what's going on, and I don't see any difference between a failing browser and a working one, so I think there's something going on in ICD. However, I know that this particular configuration isn't one that I'm likely to see at any customer site, especially since I'm using VMWare Workstation to run my VMs. So I'm just documenting this here so there's at least one Google hit on the problem, along with at least one workaround.

Tuesday, April 7, 2020

How to delete virbr0 and virbr0-nic in RHEL7

Background

I have an RHEL 7.6 VM that I clone to have new servers. This VM was installed with the Desktop profile defaults. This installed libvirt, which I normally want in my VMs, but it sometimes gets in the way. Specifically, I needed to configure two DB2 VMs with HADR and TSAM in a test environment, and I found that virbr0 and virbr0-nic don't allow the 'db2haicu' command to successfully complete. So I needed to quickly delete those interfaces.

List of steps

As root:

service libvirtd stop
systemctl disable libvirtd
ip link set virbr0 down
brctl delbr virbr0
ip link delete virbr0-nic

Caveats

I don't know if the above will correctly survive a reboot.