THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Jamie Thomson

This is the blog of Jamie Thomson, a data mangler in London working for Dunnhumby

Calling Cronacle web service QueryJob1 from PowerShell

2 blog posts in 2 days. Hell must have frozen over…

On my current project we are using Cronacle as our job scheduler and we have a need to programatically query Cronacle to ask it the status of a job. The following script accomplishes that using PowerShell:

Code Snippet
  1. function Ignore-SSLCertificates
  2. {
  3.     $Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
  4.     $Compiler = $Provider.CreateCompiler()
  5.     $Params = New-Object System.CodeDom.Compiler.CompilerParameters
  6.     $Params.GenerateExecutable = $false
  7.     $Params.GenerateInMemory = $true
  8.     $Params.IncludeDebugInformation = $false
  9.     $Params.ReferencedAssemblies.Add("System.DLL") > $null
  10.     $TASource=@'
  11.         namespace Local.ToolkitExtensions.Net.CertificatePolicy
  12.         {
  13.             public class TrustAll : System.Net.ICertificatePolicy
  14.             {
  15.                 public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)
  16.                 {
  17.                     return true;
  18.                 }
  19.             }
  20.         }
  21. '@
  22.     $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
  23.     $TAAssembly=$TAResults.CompiledAssembly
  24.     ## We create an instance of TrustAll and attach it to the ServicePointManager
  25.     $TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
  26.     [System.Net.ServicePointManager]::CertificatePolicy = $TrustAll
  27. }
  28. function Get-CronaclePassword {
  29.     $securePassword = Read-Host -Prompt "Please supply Cronacle password" -AsSecureString
  30.     $creds = New-Object System.Management.Automation.PSCredential -ArgumentList "dummyvalue", $securePassword
  31.     return $creds.GetNetworkCredential().Password
  32. }
  33. function Get-CronacleJobStatus {
  34.     Param(
  35.         [Parameter(Mandatory=$true)][string]$WSUri,
  36.         [Parameter(Mandatory=$true)][string]$CronacleUser,
  37.         [Parameter(Mandatory=$true)][string]$CronaclePassword,
  38.         [Parameter(Mandatory=$true)][string]$JobId
  39.     )
  40.     $secureCronaclePassword = ConvertTo-SecureString $CronaclePassword -AsPlainText -Force
  41.     $creds = New-Object System.Management.Automation.PSCredential ($CronacleUser, $secureCronaclePassword)
  42.     $userpasswordbase64 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("${CronacleUser}:${CronaclePassword}"))
  43.     $payload = @"
  44. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="scheduler.redwood.com">
  45.    <soapenv:Header/>
  46.    <soapenv:Body>
  47.       <sch:QueryJobRequest>
  48.          <sch:JobId>${JobId}</sch:JobId>
  49.       </sch:QueryJobRequest>
  50.    </soapenv:Body>
  51. </soapenv:Envelope>
  52. "@
  53.     Ignore-SSLCertificates
  54.     $headers = @{"Content-Type"="application/xml";"charset"="utf-8";"Authorization"="Basic $userpasswordbase64";"SOAPAction"="query/Job/QueryJob1"}
  55.     $response = Invoke-WebRequest -Headers $headers -Uri $WSUri -Method Post -Body $payload #-Credential $creds
  56.     return ([xml]($response.Content)).GetElementsByTagName("job:Status")[0].InnerText
  57. }
  58.  
  59.  
  60. $cronacleServer = Read-Host "Cronacle server (e.g. https://servername:10180)"
  61. $uri = "$cronacleServer/scheduler/api-soap/query/Job/QueryJob1"
  62. $user = Read-Host "Cronacle username"
  63. $password = Get-CronaclePassword
  64. $jobid = Read-Host "JobId?"
  65.  
  66. Get-CronacleJobStatus -WSUri $uri -CronacleUser $user -CronaclePassword $password -JobId $jobid
Published Friday, January 22, 2016 4:06 PM by jamiet
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

tom said:

I Will Provide Seo Blog Comment Service. & niche relevant blog comment service we provide a quality service with 100% Buyer satisfaction and My team Believed in Quality work not Quantity Contact me Now 24/7. https://www.fiverr.com/jj_seoservice

April 30, 2017 5:06 PM

Leave a Comment

(required) 
(required) 
Submit

This Blog

Syndication

Privacy Statement