Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Windows Sensu Client Script v0.1
- # Installs and configures sensu (client)
- #
- # Set vars
- Get-ChildItem Env:COMPUTERNAME | select -exp value -OutVariable HOSTNAME >$null
- Get-NetIPAddress | Where-Object {$_.AddressFamily -contains "IPv4"} | Where-Object {$_.InterfaceAlias -like "Local*"} | select -exp IPAddress -OutVariable LOCALIP >$null
- # Download and install msi
- Import-Module BitsTransfer
- Start-BitsTransfer -source https://core.sensuapp.com/msi/sensu-0.23.0-1.msi
- .\sensu-0.23.0-1.msi /passive
- $oldPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
- $newPath=$oldPath+’;C:\opt\sensu\embedded\bin\’
- Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH –Value $newPath
- sensu-install -p sensu-plugins-windows:0.0.10
- # build and echo configs
- echo '{
- "rabbitmq": {
- "host": "1.1.1.1",
- "port": 5672,
- "vhost": "/sensu",
- "user": "sensu",
- "password": "lol_you_almost_got_me"
- }
- }' > "C:\opt\sensu\conf.d\rabbitmq.json"
- $client1 = '{
- "client": {
- "name": "'
- $client2 = '",
- "address": "'
- $client3 = '",
- "subscriptions": [ "none" ]
- }
- }'
- echo $client1$HOSTNAME$client2$LOCALIP$client3 > "C:\opt\sensu\conf.d\client.json"
- $CHECK1 = '{
- "checks": {
- "Disk": {
- "command": "check-windows-disk.rb -w 85 -c 95",
- "standalone": true,
- "interval": 120
- },
- "CPU": {
- "command": "check-windows-cpu-load.rb -w 85 -c 95",
- "standalone": true,
- "interval": 60
- },
- "RAM": {
- "command": "check-windows-ram.rb -w 85 -c 95",
- "standalone": true,
- "interval": 60
- },
- "Uptime": {
- "command": "metrics-windows-uptime.rb",
- "standalone": true,
- "interval": 60
- },
- "RDP_Service": {
- "command": "check-windows-service.rb -p '
- $SERVICENAME1 = "`'Remote Desktop Services`'"
- $CHECK2 = ' -w 300",
- "standalone": true,
- "interval": 60
- }
- }
- }'
- echo $CHECK1$SERVICENAME1$CHECK2 > "C:\opt\sensu\conf.d\check_windows.json"
- #create and start the service
- echo '
- <service>
- <id>sensu-client</id>
- <name>Sensu Client</name>
- <description>This service runs a Sensu client</description>
- <executable>C:\opt\sensu\embedded\bin\ruby</executable>
- <arguments>C:\opt\sensu\embedded\bin\sensu-client -c C:\opt\sensu\config.json -d C:\opt\sensu\conf.d -l C:\opt\sensu\sensu-client.log</arguments>
- </service>
- ' > "C:\opt\sensu\bin\sensu-client.xml"
- sc create sensu-client start= delayed-auto binPath= c:\opt\sensu\bin\sensu-client.exe DisplayName= "Sensu Client"
- sc sensu-client start
Advertisement
Add Comment
Please, Sign In to add comment