Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Created December 5, 2014 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstreefkerk/0678538586a8682b3252 to your computer and use it in GitHub Desktop.
Save dstreefkerk/0678538586a8682b3252 to your computer and use it in GitHub Desktop.
Tickets Open widget update code. To be used with a "Number and Secondary Stat" widget: https://developer.geckoboard.com/#number-and-secondary-stat
$apikey = "paste in your API key here"
$geckoPushUrl = "paste in your push URL here"
# Get the count of open tickets from the database
$openTickets = Invoke-Item spiceworks: -sql 'select count() as "count" from tickets where status == "open"'
#Construct a here-string with the required json format
$jsonstream = @"
{
"api_key":"APIKEY",
"data": {
"type" : "reverse",
"item" :
[
{ "text" : "TICKETTEXT","value" : TICKETSOPENVALUE}
]
}
}
"@
$ticketText = if ($newToday.count -eq 1) { "Ticket Open" } else { "Tickets Open" }
$jsonstream = $jsonstream.Replace("TICKETSOPENVALUE",$($openTickets.count))
$jsonstream = $jsonstream.Replace("APIKEY",$apikey)
$jsonstream = $jsonstream.Replace("TICKETTEXT",$ticketText)
#The line of code will only work in PowerShell V3
#Invoke-WebRequest -Method Post -Body $jsonstream -Uri $geckoPushUrl
#This should work in V2 also
$client = new-object system.net.webclient
$client.UploadString($geckoPushUrl,$jsonstream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment