Skip to content

Instantly share code, notes, and snippets.

View Sam-Martin's full-sized avatar

Sam Martin Sam-Martin

View GitHub Profile
@Sam-Martin
Sam-Martin / Teamcity-Build-Agent-Pester-Tests.ps1
Created November 1, 2016 16:54
Run Pester Tests Remotely
$tests = Get-Content "%teamcity.build.checkoutDir%\TeamCity-Build-Agents.tests.ps1" | Out-String
$scriptblock = {
param($script)
$scriptFile = "$env:temp\TeamCity-Build-Agents.tests.ps1"
Set-Content $scriptFile -Value $script
Invoke-Pester -Script $scriptFile -PassThru 6> $null 2> $null
}
$BuildAgents = @(
'tc-buildagent-01',
index=_internal source=*license_usage.log type="Usage" splunk_server=* | timechart span=1d eval(round(sum(b)/1024/1024/1024,5)) as GB | sort _time
@Sam-Martin
Sam-Martin / PowerShell Zabbix API Example.ps1
Created August 3, 2016 15:53
PowerShell Zabbix API Example
if(!$credential){
$credential = Get-Credential
}
$baseurl = 'http://zabbix.global.root'
$params = @{
body = @{
"jsonrpc"= "2.0"
"method"= "user.login"
"params"= @{
"user"= $credential.UserName
@Sam-Martin
Sam-Martin / IIS
Last active August 1, 2016 13:53
Useful Splunk Queries
# Show requests from IE on XP
index=* AND cs_User_Agent=*| eval windows_xp_and_ie=if(match(cs_User_Agent,".*MSIE.*5.1.*"),"TRUE","FALSE") | stats count by windows_xp_and_ie
@Sam-Martin
Sam-Martin / PagerdutyDashboard.xml
Created May 30, 2016 14:28
PagerDuty Splunk Dashboard
<dashboard>
<label>Operational Dashboard</label>
<row>
<panel>
<chart>
<title>Total callouts last 30 days</title>
<search>
<query>index="pagerduty" AND ("channel.notification.type" = *_push_notification OR "channel.notification.type" = SMS OR "channel.notification.type" = Phone) |
timechart count by "user.summary"</query>
<earliest>-30d@d</earliest>
@Sam-Martin
Sam-Martin / PagerDutyToSplunk.py
Last active May 27, 2016 16:25
PagerDutyToSplunk.py
import os
import json
import urllib
import urllib2
from datetime import datetime
from datetime import timedelta
import json
@Sam-Martin
Sam-Martin / Get-StationsInLondon
Last active May 21, 2016 20:02
A quick PowerShell way to get the lats and longs of all stations in the Greater London area (and a bit more besides)
$hashResult = @{}
if(!$TubeStationsRAW){
$TubeStationsRAW =@()
$page = 0
while(1){
$page += 1;
Write-Verbose "Looking at page $page"
$result = $(invoke-webrequest "https://api.tfl.gov.uk/StopPoint/Mode/tube,overground,national-rail?page=$page").content | ConvertFrom-Json
if(!$result){
return
@Sam-Martin
Sam-Martin / Update-PingdomChecksIntegrationID.ps1
Created May 18, 2016 09:38
Update all your pingdom checks to use a single ID
$VerbosePreference = "Continue"
if(!$cred){
$cred = Get-Credential
}
$IntegrationID = 707
if($(Read-Host "Warning, this will replace all checks' integrations with ONLY integration ID $integrationID, do you wish to continue? y/n") -ne 'y'){
return;
}
$params = @{
uri = "https://api.pingdom.com/api/2.0/checks"
@Sam-Martin
Sam-Martin / Pingdom2HipChat.ps1
Last active May 17, 2016 10:36
Pingdom2HipChat
# Get input and output params (as named in our function.json)
$result = $Env:res
$requestPath = $env:req
$executionPath = Split-Path -parent $PSCommandPath
$tempPath = Split-Path -parent $env:req
# Read the input from file and parse it to an object
[Console]::WriteLine("Reading input from $env:req")
$requestObj = Get-Content $requestPath | Out-String | ConvertFrom-Json
@Sam-Martin
Sam-Martin / Get-ServiceWPF.ps1
Last active April 28, 2016 08:11
Get-Service WPF PowerShell Get-PSUGUK 2016.04.27
Add-Type -AssemblyName PresentationFramework
[xml]$XAMLWindow = '
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="Auto"
SizeToContent="WidthAndHeight"
Title="Get-Service">
<ScrollViewer Padding="20">