Not long ago @serena posted: Configuring SAM to monitor REST API endpoints And if you have not read it you should. Lots of great data lies just beneath the surface of many applications that your company uses, even the ones that are hosted or Saas. Rest is where applications will be placing data we used to get from Performance Counters, SNMP or WMI. Once you dip your toe in, its not a scary place, and the rest API monitor really simplified getting those stats.
But I hope you don't stop there. Getting stats on how well an application works is one thing, but many applications let you use it via rest as well. Testing the same functions that users need lets you have a canary in the coal mine. You will need to break out your scripting talents, but if you need help Thwack is only a few clicks away.
I am not a phone expert. No one on my team is either. I want faxing to go away and be replaced by more modern methods of communication.
But we do support the application, Rightfax, that our organization uses to handle faxing. What we have come to understand is that faxing is a surprisingly old technology and many things can break it. One of the engineers I work with has spent years making the best out of our faxing environment, and its in a very good place. But it became clear that faxing wouldn’t always work, especially considering how many things were out of our control. And sometimes when everything looked good on the servers and in the application, outbound faxes would queue up. And sometimes we just didn’t get faxes. Was it the application we support? Was it our phone provider, or the session broker we talked to?
We sat down to brainstorm what we could to give us better information. What it took was several experts working together to create a test fax send and receive.
Recently we added a rightfax module to give another application API access to the server. Ironically OpenText didn’t make it easy to get to what I can do, but the Internet is a big place, and you can find other people who have done similar things. I used JSON to create the request and read back data. And it just so happens that I had some exposure to those methods when I tried Leon’s Slack integration.
First we made a user in the application with access to a test mailbox and rights to use the API. My RightFax expert handled this. We also made sure that the extension we choose was generally completely useless on our system, and that it would get routed out of our server, then bounce back to it from a session broker that handles our phone system.
I choose to use PowerShell to do the work, via the Windows PowerShell Monitor component, it was the path of least resistance. Below is the script I wrote to connect to the server, send a fax, then check on the job status. We know that most 1-page faxes (I just send a cover page) get sent within seconds and our slowest time we have enough capacity for that job to complete within a minute or two. We mark the job failed after 5 minutes. You could easily return specific error codes and job duration, but this met our needs, and was easy to alert on since it is basically a pass/fail check.
$CRED = Get-Credential '${CREDENTIAL}'$SERVER = '${IP}'$UriSendJob = 'https://'; + $SERVER + '/rightfax/api/sendjobs'## Set PowerShell session to ignore certificate statusif (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type) { $certCallback = @ using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; public class ServerCertificateValidationCallback { public static void Ignore() { if(ServicePointManager.ServerCertificateValidationCallback ==null) { ServicePointManager.ServerCertificateValidationCallback += delegate ( Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors ) { return true; }; } } }@ Add-Type $certCallback}[ServerCertificateValidationCallback]::Ignore()## Build the header for the REST call to initiate a new fax.## Update '99999' with the value of an inbox that can receive test faxes$BodyJSONSendJob = @{Recipients":[{"Destination":"99999","Name":"Test Script Send"}]}"@## Send the test fax. This fax will be 1 page since the system settings create a cover sheet for each fax, and we add zero additional pages$ResponseSendJob = Invoke-WebRequest -Uri $UriSendJob -ContentType 'application/json' -Method 'Post' -body $BodyJSONSendJob -UseBasicParsing -Credential $CRED$Data = $ResponseSendJob.StatusDescription$retrycount = 0do { if ($Data -notlike 'Created') { sleep -seconds 1 $retrycount++ $ResponseSendJob = Invoke-WebRequest -Uri $UriSendJob -ContentType 'application/json' -Method 'Post' -body $BodyJSONSendJob -UseBasicParsing -Credential $CRED } $Data = $ResponseSendJob.StatusDescription}until (($Data -like 'Created') -or ($retrycount = 3))if ($Data -notlike 'Created') { Write-Host "Message.Result: Test Job not created"; Write-Host "Statistic.Result: 1"; Exit 1}$CreatedJobID = ($ResponseSendJob | ConvertFrom-Json).id$UriCreatedJob = 'https://'; + $SERVER + '/RightFax/API/Documents?filter=job&jobid=' + $CreatedJobID$count = $null$Status = $nulldo { sleep -seconds 1 $ResponseCreatedJob = Invoke-RestMethod -Uri $UriCreatedJob -Credential $CRED $count++ ## If you want to wait longer than 5 minutes to send a fax, adjust the number below from 300 seconds to what you need if ($count -ge 300) { Write-Host "Message.Result: Send taking longer than 5 minutes"; Write-Host "Statistic.Result: 3"; Exit 1 }}until ($ResponseCreatedJob.items.statustext -like 'Completed')$ExitStatus = $ResponseCreatedJob.items.conditionWrite-Host "Message.Result: $ExitStatus";Write-Host "Statistic.Result: 0";Exit 0 This runs in addition to the normal stuff you might monitor for an application. We have the database monitored, services, processes, IIS, port checks and events from the server as well. But nothing says that faxing is working like sending a fax. Also, the API sends work to any server in the cluster, so I may make the API call on one server, and another sends the fax. That means you should only run this on one server, and if you want to get a check that the API service works, use the built in API call monitor for each server.
Hopefully someone finds this useful, or decides to dive into a rest monitor of thier own.