locked
Need help with script to automate the passing of SCOM alerts to LANDesk RRS feed

  • Question

  • Hello everyone,

    I need to write a script that will take input parameters from SCOM via a command channel and then modify one of the parameters and finally pass all of the paramaters through to another exe for processing. The problem is that SCOM will not send through a short name for a server. Instead, it will only send through the FQDN. I need to send 5 parameters from SCOM to an executable in a certain order and format in order to open an alert ticket and properly populate the alert ticket fields. The most important parameter is the configuration item. Basically, SCOM will only send FQDN and LANDesk will not process it that way.

    All I need to do is have powershell receive 3 variable parameters from SCOM and then modify only the 3rd variable. Finally, I need it to load the 2 original variables it received and the modified 3rd variable and push it to the other exe for LANDesk to receive.

    Here is how I have it setup so far from the SCOM command channel

    command file path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    Command line parameters: -command "E:\scripts\ldsd\scomtest2.ps1" "$Data[Default='Not Present']/Context/DataItem/AlertName$" "$Data[Default='Not Present']/Context/DataItem/AlertDescription$" "$Data[Default='Not Present']/Context/DataItem/ManagedEntityPath$\$Data[Default='Not Present']/Context/DataItem/ManagedEntityDisplayName$"

    Startup folder for the command line: E:\scripts\ldsd\

    I know the command channel works and launches the PS Scripot, but the script doesn't work. This is what the script looks like:

    cls

    Param(
          [string]$title
          [string]$description
          [string]$fqdn

    # Find the first instance of a period in the fqdn string and record the character position
    $pos = $fqdn.IndexOf(".")

    # return the text prior to the first period - resulting in the single space name
    $singlespacename = $fqdn.Substring(0,$pos)

    C:\LanDesk\PostEvent.exe "Alert" "SCOM" "$title" "$description" "$singlespacename"

    All I need is for the 3 parameters to load into the script and for the script to modify the FQDN of the server name to the short name and then execute the LanDesk executable, sending the 3 variables. It should be very simple but I ahve limited experience with powershell.  This entire script is for nothing more than to modify the FQDN variable to a short name (without periods) and send it away. If LanDesk could accept the FQDN and match it to a CI properly, this wouldn't be needed at all. If that were the case, I could simply call the landesk executable and send the paramters from SCOM right to it. I can do that already, but the FQDN will not match a configuration item in landesk, so it does not meet our needs.

    Any help much appreciated!

    Thursday, June 15, 2017 11:02 PM

All replies

  • You are missing a closing paren on your Param Statement.

    Don't use quotes:

    Start-Process -FilePath C:\LanDesk\PostEvent.exe -ArgumentList @('Alert', 'SCOM', $title, $description, $singlespacename) -NoNewWindow

    For LanDesk issues you will have to post in a LanDesk forum.


    \_(ツ)_/



    • Edited by jrv Thursday, June 15, 2017 11:19 PM
    Thursday, June 15, 2017 11:17 PM
  • Thank for your reply!

    I was able to get the script cleaned up and working. However, I'm still not getting the desired output. I tried a couple different methods. The defined variable for "singlespacename" is not coming out correctly. This is not a landesk issue as the proper parameters sent to landesk activate the process just fine. The problem is getting the FQDN from SCOM to send to landesk as the simple name instead of the FQDN.

    Here's the new scripts:

    Param(
          [string]$title,
          [string]$description,
          [string]$fqdn
    )

    cls 

    $singlespacename = $fqdn.Split(".")[0]

    $command = 'C:\LanDesk\PostEvent.exe "Alert" "SCOM" ' + '"' + $title + '" ' + '"' + $description + '" ' + '"' + $singlespacename + '"'
    $scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock($command)  
    Invoke-Command -ScriptBlock $scriptblock 

    #C:\LanDesk\PostEvent.exe "Alert" "SCOM" "$title" "$description" "$singlespacename"

    and

    Param(
          [string]$title,
          [string]$description,
          [string]$fqdn
    )

    cls 

    # Find the first instance of a period in the fqdn string and record the character position
    $pos = $fqdn.IndexOf(".")

    # return the text prior to the first period - resulting in the single space name
    $singlespacename = $fqdn.Substring(0,$pos)

    $command = 'C:\LanDesk\PostEvent.exe "Alert" "SCOM" ' + '"' + $title + '" ' + '"' + $description + '" ' + '"' + $singlespacename + '"'
    $scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock($command)  
    Invoke-Command -ScriptBlock $scriptblock

    #C:\LanDesk\PostEvent.exe "Alert" "SCOM" "$title" "$description" "$singlespacename"

    Thanks for your time


    Saturday, June 17, 2017 12:30 AM
  • We have no idea what you are asking. What is a "simple name"?

    If you use Start-Process you will avoid all of the quoting issues.  Your approach will run into command parsing issues.

    Without a better definition of what you are trying to do it will be hard to help you.


    \_(ツ)_/

    Saturday, June 17, 2017 12:44 AM
  • I need to send alerts from SCOM to LANDesk. This is accomplished through calling a LANDesk executable. The landesk exe will take the input and populate a landesk ticket. The problem is that landesk will not interpret an FQDN and match it to a configuration item in landesk. That paramter must exactly equal a landesk CI to populate. Without ridiculous amounts of modification in scom, I cannot send the host name of the server affected in any other form than FQDN. I need to send JUST the host name, like the netbios name "hostname" not "hostname.xxx.xxx.xxx" The script I am working on has one goal: to remove the text from the first period in the FQDN and thereafter and keep what comes before. That is the only point of the whole thing. Instead of sending the parameters directly from scom to the ld exe, I am sending the parameters to this script with the goal of modifying the fqdn and outputting the same exact input, but with modifications to the landesk exe.

    Thanks

    Monday, June 19, 2017 6:35 PM
  • $hostname = ($fqdn -split '\\')[0]

    \_(ツ)_/

    • Proposed as answer by Hello_2018 Friday, July 7, 2017 4:58 AM
    Monday, June 19, 2017 6:41 PM