Skip to content

Instantly share code, notes, and snippets.

@ryosms
Last active December 20, 2019 06:53
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 ryosms/139a167a34c272ac110f27898c75e858 to your computer and use it in GitHub Desktop.
Save ryosms/139a167a34c272ac110f27898c75e858 to your computer and use it in GitHub Desktop.
Windowsのバッチ処理の実行結果をmkr wrapとmkr annotationsで確認する
param(
[int]$ExitCode = 0,
[int]$WaitSeconds = 60
)
Write-Output("Start awesome-batch (WaitSeconds: {0})" -f $WaitSeconds)
# wait 1 minute
Start-Sleep -Seconds $WaitSeconds
Write-Output("Complete awesome-batch (Exit: {0})" -f $ExitCode)
exit $ExitCode
param(
[switch]$Critical,
[string]$ServieName = "mkr-test",
[string]$RoleName = "mkr",
[string]$AnnotationTitle = "Awesome Batch Result"
)
$env:Path="$env:Path;C:\Program Files (x86)\Mackerel\mackerel-agent"
$ExitCode = 0
if($Critical) {
$ExitCode = 1
}
function GetEpoch($date) {
return [Math]::Truncate(($date - (Get-Date("1970/01/01 00:00:00 GMT"))).TotalSeconds)
}
$from = $(GetEpoch(Get-Date))
# Build full path to call batch script
$batch = Join-Path $(Split-Path -Parent $($MyInvocation.MyCommand.Path)) "awesome-batch.ps1"
$result = $(mkr wrap `
--name "awesome batch" `
--detail `
--auto-close `
-- powershell $batch -ExitCode $ExitCode)
$exit_code = $LastExitCode
$to = $(GetEpoch(Get-Date))
# post graph annotation
mkr annotations create `
--service "$ServieName" `
--from $from `
--to $to `
--title "$AnnotationTitle" `
--description "$result"
exit $exit_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment