Skip to content

Instantly share code, notes, and snippets.

@rayterrill
Created July 14, 2017 18:20
Show Gist options
  • Save rayterrill/77597ed9232303b60f4dee12e589ee41 to your computer and use it in GitHub Desktop.
Save rayterrill/77597ed9232303b60f4dee12e589ee41 to your computer and use it in GitHub Desktop.
@{
# Point to your module psm1 file...
RootModule = 'SystemStatus.psm1'
# Be sure to specify a version
ModuleVersion = '0.0.1'
Description = 'PoshBot module for getting System Status from Cachet'
Author = 'Ray Terill'
CompanyName = 'Community'
Copyright = '(c) 2017 Ray Terrill. All rights reserved.'
PowerShellVersion = '5.0.0'
# Generate your own GUID
GUID = '3d0a33cd-bef0-4cf0-99e3-fff9aba222b8'
# We require poshbot...
RequiredModules = @('PoshBot')
# Ideally, define these!
FunctionsToExport = '*'
PrivateData = @{
# These are permissions we'll expose in our poshbot module
Permissions = @(
@{
Name = 'read'
Description = 'Run commands that query Acme systems'
}
)
} # End of PrivateData hashtable
}
# Slack text width with the formatting we use maxes out ~80 characters...
$Width = 80
$CommandsToExport = @()
function Get-SystemStatusViaSlack {
<#
.SYNOPSIS
Get System Status from outages.portofportland.com via Slack
.EXAMPLE
!sysstemstatus
#>
[PoshBot.BotCommand(
CommandName = 'systemstatus',
Aliases = 'Get-SystemStatus',
Permissions = 'read'
)]
$res = Invoke-WebRequest https://cachetio.com/api/v1/components -UseBasicParsing
$data = $res.Content | ConvertFrom-JsonNewtonSoft
#Create Table object
$table = New-Object system.Data.DataTable "System Status"
#Define Columns
$col1 = New-Object system.Data.DataColumn System,([string])
$col2 = New-Object system.Data.DataColumn Status,([string])
#Add the Columns
$table.columns.add($col1)
$table.columns.add($col2)
foreach ($d in $data.data) {
#Create a row
$row = $table.NewRow()
#Write-Host "$($d.name) - $($d.status_name)"
#Enter data in the row
$row.System = $d.name
$row.Status = $d.status_name
#Add the row to the table
$table.Rows.Add($row)
}
$o = $table | Format-Table -AutoSize -Wrap | Out-String -Width $Width
New-PoshBotCardResponse -Type Normal -Text $o
}
$CommandsToExport += 'Get-SystemStatusViaSlack'
Export-ModuleMember -Function $CommandsToExport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment