Introduction
I was impressed by the article on how to manage the BMC Remedy's ticketing system using the .NET Framework posted here; I followed all the steps and easily achieved the task. After playing around for a week with my code, I realized that it could be possible to create a simple and more powerful tool similar to the one already distributed from BMC named runmacro.
Unfortunately, the runmacro utility allows you to run a macro with some limitations. For example, it is not possible to close or update tickets or it can't run macros in turn! (only one macro per time).
Background
The prerequisite for having the binary working is to download the .NET API and register the path in the environment variable of your system ( es. add "C:\ARAPI.NET" inside your system and you should be done).
Because I'm also consulting for a phone company and we interact very frequently with the trouble ticketing system, my idea was to have a command line tool in a form like below:
macro.exe -u <user> -p <password> -s <server> -n <port> -f <remedy-form> -m <macro> <options> -o|-c|-d
With such a tool, all operators would open service calls quickly, ensuring the typical activity tracking procedure that companies demand them.
Another useful idea would be to embed the tool inside a scripting engine for integrating the utility inside other platforms that use the Trouble Ticketing system for opening service request when something triggers. (Es. SIEM, monitoring systems, backup softwares, etc. )
Using the Code
The project is a typical Visual Studio solution that uses, for controlling the command line arguments and exceptions, the great plossum library also from the CodeProject family.
Once compiled, if everything is in the right place and you've linked all the right libraries, you should obtain this menu:
C:\>eRemedyMacro.exe
eRemedyMacro version 1.0
Copyright (C) Jack Ross 2014
For support, write an mail at: luce2047@hotmail.com
Errors:
* One of the options "a", "c", "d", "o" must be specified
Options:
-e, on discovery specify whether
--no-empty-fields to print empty fields or not.
-f, --form Specifies the form
-h, --help Shows this help text
-m, --macro Specifies the macro
-n, --port-number Specifies the port
-p, --password Specifies the password
-r, --remark Specifies the final solution when closing
-s, --server Specifies the server
-u, --user Specifies the account username
Commands:
-a, --approve Approve a ticket or a list of tickets if specified a file
-c, --close Close a ticket or a list of tickets if specified a file
-d, --discovery Discovery ticket fields
-o, --open Open a ticket
As you can see, it is very intuitive so let me show you the basic steps for getting started with the macro serialization!
The first step is to create a macro and from there going through the other features; doing a new macro is an easy step that can be done with an interesting feature I added: the ability of "scan" the remedy structure, as configured from the Remedy administrator, by launching this command:
eRemedyMacro.exe -u user -p password -s server -n port -f "FormName" -d <TT number>
The discovery feature is probably the glossy part of the tool! When launched against an existing ticket, it prints out every field of the form with the ability of understanding also the entry value type.
This last option has to be enabled recompiling the code changing this block as shown (lines 345-349):
if (entry.Value.GetType().ToString() == "System.String")
{
Console.WriteLine("{0} = {1} {2}", entry.Key, entry.Value, entry.Value.GetType());
}
I also preferred not to print DBNull
values for my convenience that I'll explain in short but if you think that they can be useful for mapping your own structure, simply delete lines 350-353.
Printing out a ticket structure, especially when the ticket is just opened, is very useful for creating a macro template; with such option if you append the > operator to the command above and save all in a text file you create the basic macro template of your Remedy Site!
That's the reason why I preferred not to print the DBNull
values and if everything goes well and you have the appropriate permissions on your account, you should obtain a file similar to the block below:
...
1251000070 = "MY_REMEDY_GROUP";
536870975 = "MY_SURNAME";
536870971 = "luce2047@hotmail.com";
536870970 = "Jack Ross";
536870930 = "[BMC Eremedy] welcome to the remedy TT case object";
536870923 = "Priority";
536870920 = "USERNAME";
1252000082 = 1;
1320000052 = "DEFAULT";
1261000030 = "Option_1";
1360000010 = "Option_2";
1261000020 = "Option_3";
1261000010 = "Option_4";
1251000190 = "Option_5";
7 = 1;
... and so on...
On your installation, the dictionary will have different values and mappings but this example will give you an idea of what will be printed out by the discovery option when you launch the tool on an existing item.
Take a look to the last entry 7 = 1: this is the entry in my environment that controls the ticket state (opened, closed, confirmed, etc.) I could have thought of configuring this parameter in the command line arguments to let you decide which one is the one matching your installation but I preferred to have it embedded in the code and obviously, after having made a good discovery, while recompiling ensure that you match it with the appropriate value of your remedy installation.
Having a macro up, we can start now to open a ticket with this command:
eRemedyMacro.exe -u user-p password -s ip-server -n port -f "FormName" -m myCustoMacro -o
Created Ticket: TT0000001234567
If everything goes well, you've successfully opened a ticket.
For closing a ticket, you need to launch a slightly different command:
eRemedyMacro.exe -u user -p password -s server -n port -f "FormName" -r "remark" -c "ticket|list"
Closed Ticket: TT0000001234567
As you can see, it is possible to close one ticket at a time or even pass a list of tickets inside a text file that uses as separator a new line character; the same is for the confirmation:
eRemedyMacro.exe -u user -p password -s server -n port -f "FormName" -a "ticket|list"
Confirmed Ticket: TT0000001234567
The difference between confirming and closing is that with the first you acknowledge the request, but with the second you effectively close the connection to the case. (Every good it-worker will suddenly understand what I mean and at this point you don't care about the case anymore unless someone else is going to re-open a previous case you've already confirmed.)
Let's now have a deeper review of this code: you have a single file Program.cs file with only two classes inside the Options, dedicated to the command line arguments and exceptions, and the eRemedyMacro
, the main class, and all you have to do for setting up the Visual Studio is to create an empty CLI project and link references from the BMC .NET Framework (BMC.ARSystem.dll and BMC.ARSystem.Utilities.Common.dll) and the plossum library (Plossum CommandLine.dll).
This is quite easy I can guess so I leave you the fun of connecting libraries and assemblies :) but for any inconvenience, you can write a help request in the comments and I'll share the configurations with the community.
And that's it. I hope you enjoyed with this piece of code and you can find it useful for your needs; some colleagues of mine were enthusiastic (Microsoft MCITP DBAs and other administrators) about this tool and they asked me to build a script for creating macros starting from a macro template and changing only the main subject; I was very proud of my work and that's why I share this snippet (a Powershell script) in the hope you can find it useful for your needs!
<#-------------------------------------------------------------------------------
# Name: Create macro script
# Purpose: Script for creating Remedy macro starting from a template
# and changing only the object.
# It takes three parameters as arguments of the procedure
# Es. .\macroTemplate.ps1 <list> <fileNameSequence> <macro>
#
# Author: Jack Ross
# Created: 28/03/2014
# Support: luce2047@hotmail.com
#-------------------------------------------------------------------------------
#>
$reader = [System.IO.File]::OpenText($args[0])
try {
for(;;) {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
# process the line
write-host "$($args[1])-$($(get-date -f MM-dd-yyyy_HH_mm_ss)).txt"
Start-Sleep -s 1
(Get-Content $args[2]) |
Foreach-Object {
$_ -replace "\[BMC Eremedy\] welcome to the remedy TT case object", "$($line)"
} | Out-File "$($args[1])-$($(get-date -f MM-dd-yyyy_HH_mm_ss)).txt"
}
}
finally {
$reader.Close()
}
With this last variant, the BMC tool now has no secrets for you! And you can really serialize all the tickets you need as much as you want. Remember to use macro responsibly and not abuse the tool flooding the BMC database of rubbish!