Open MartynKeigher opened 8 years ago
How about having your Powershell code post to your dashboard using Curl for windows? Alternatively, I believe there are methods in Powershell to use HTTP (such as: Invoke-WebRequest).
Unless I'm missing the gist of your question, gather the data you want using Powershell, then post the result to the dashboard using HTTP. If you need to do this periodically, run the Powershell script via a scheduled task. I do something similar using VBScript.
It may also be possible to run your Powershell script from Ruby using System or Exec commands and pass the data via a file dump. Ruby calls a batch file, which runs a Powershell script and dumps data to a temp file, Ruby then reads the temp file data and posts to the dashboard. Have not done this myself but seems possible.
SomeHuman
Martyn,
Somehuman is correct in using Invoke-Request. Here is an example of pulling total # of VMs from Virtual Center via PowerCli and posting to Dashing via Rest.
`if ( !(Get-Module -Name VMware.VimAutomation.Core )) { “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1” }
function Postto-Dashing { <# .Synopsis Post text to a Dashing Widget .DESCRIPTION Long description .EXAMPLE Postto-Dashing -uri "http://255.255.255.255:3030/widgets/welcome" -text ”New message from Powershell” -authToken "Powershell" .INPUTS $uri,$text,$user .NOTES All Inputs are Mandatory
[CmdletBinding()]Param
(
# Incoming Webhook
[Parameter(Mandatory=$true
)]
$uri,
# Body of message
[Parameter(Mandatory=$true
)]
$text,
# Username to post as
[Parameter(Mandatory=$true
)]
$authToken
)
$Payload = @{auth_token=$authToken;current=$text}
Invoke-RestMethod -Uri $uri -Method Post -ContentType 'application/json' -Body (ConvertTo-Json $Payload)
}
$user = '' $File = '' $creds =New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)
$vcenters = ('') $vms = @() foreach ($vcenter in $vcenters) { Connect-VIServer $vcenter -Credential $creds $vms += Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} Disconnect-VIServer -Confirm:$false }
$totalCPU =
$authToken = 'YOUR_AUTH_TOKEN' $uri = '' Postto-Dashing -uri $uri -text $vms.Count.ToString() -authToken $authToken`
For the Graph widget: https://github.com/Smashing/smashing/wiki/How-To:-Setup-a-Graph
$DBURL = "http://dashboardserver:3030/widgets/" $metric="yourmetric" $cpuArray = @{x=1980;y=1323},@{x=1981;y=53234},@{x=1982;y=2344} $jArray = ConvertTo-Json $cpuArray $body = '{ "auth_token": "YOUR_AUTH_TOKEN", "points": ' + $jArray + ' }' Invoke-RestMethod -UseBasicParsing $DBURL$metric -ContentType "application/json" -Method POST -Body $body
Hey all,
I am looking to pull in values onto my dashboard based on results I get via Powershell. Not looking for anything that's too far-fetched (for now!), a simple proof of concept would be something like
(Get-Hotfix).count
, that returns a simple numeric result such as45
.Anyone already doing this??
://mk