Skip to content

Instantly share code, notes, and snippets.

@Deconstrained
Created March 16, 2017 16:48
Show Gist options
  • Save Deconstrained/713694f3e100cf19612d2e0e31c1b00d to your computer and use it in GitHub Desktop.
Save Deconstrained/713694f3e100cf19612d2e0e31c1b00d to your computer and use it in GitHub Desktop.
PagerDuty API connection test for Windows-based monitoring and integration tools.
' Copyright (c) 2016, PagerDuty, Inc. <info@pagerduty.com>
' All rights reserved.
'
' Redistribution and use in source and binary forms, with or without
' modification, are permitted provided that the following conditions are met:
' * Redistributions of source code must retain the above copyright
' notice, this list of conditions and the following disclaimer.
' * Redistributions in binary form must reproduce the above copyright
' notice, this list of conditions and the following disclaimer in the
' documentation and/or other materials provided with the distribution.
' * Neither the name of PagerDuty Inc nor the
' names of its contributors may be used to endorse or promote products
' derived from this software without specific prior written permission.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
' ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY
' DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
' This script tests connecting to PagerDuty.
On Error Resume Next
' Constants and shell object used for logging to the Windows Application Event Log
Const EVENT_SUCCESS = 0
Const EVENT_ERROR = 1
Const EVENT_WARNING = 2
Const EVENT_INFO = 4
Set objShell = WScript.CreateObject("WScript.Shell")
' Set the API endpoint and alert file directory we're working with, and whether
' you want successful calls to be logged in the Windows Application Event Log.
' NOTE: Trailing backslash is required for QueuePath!
Dim URL
URL = "https://api.pagerduty.com/agent/2014-03-14/heartbeat"
Set objHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
Err.Clear
WScript.Echo "Opening connection to PagerDuty."
objHTTP.Open "GET", URL, False
objHTTP.Send
' Log connection failures in case the system isn't able to resolve
' the domain or server isn't responding at all.
If Err.Number <> 0 Then
WScript.Echo "ERROR: Couldn't connect to PagerDuty. Check Windows Application Event Log for details."
WScript.Echo "Couldn't connect or send data to PagerDuty." & vbNewLine & vbNewLine &_
"Error Number: " & Err.Number & vbNewLine &_
"Source: " & Err.Source & vbNewLine &_
"Description: " & Err.Description & vbNewLine &_
"Help File: " & Err.HelpFile & vbNewLine &_
"Help Context: " & Err.HelpContext
Else
Status = objHTTP.Status
Response = objHTTP.responseText
WScript.Echo "Got response from PD Agent heartbeat in the API; Status: " & Status
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment