Guest User

Sensu Install Windows

a guest
Apr 14th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Windows Sensu Client Script v0.1
  2. # Installs and configures sensu (client)
  3. #
  4. # Set vars
  5. Get-ChildItem Env:COMPUTERNAME | select -exp value -OutVariable HOSTNAME >$null
  6. Get-NetIPAddress | Where-Object {$_.AddressFamily -contains "IPv4"} | Where-Object {$_.InterfaceAlias -like "Local*"} | select -exp IPAddress -OutVariable LOCALIP >$null
  7. # Download and install msi
  8. Import-Module BitsTransfer
  9. Start-BitsTransfer -source https://core.sensuapp.com/msi/sensu-0.23.0-1.msi
  10. .\sensu-0.23.0-1.msi /passive
  11. $oldPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
  12. $newPath=$oldPath+’;C:\opt\sensu\embedded\bin\’
  13. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH –Value $newPath
  14.  
  15. sensu-install -p sensu-plugins-windows:0.0.10
  16.  
  17. # build and echo configs
  18. echo '{
  19.     "rabbitmq": {
  20.         "host": "1.1.1.1",
  21.         "port": 5672,
  22.         "vhost": "/sensu",
  23.         "user": "sensu",
  24.         "password": "lol_you_almost_got_me"
  25.     }
  26. }' > "C:\opt\sensu\conf.d\rabbitmq.json"
  27.  
  28. $client1 = '{
  29.     "client": {
  30.         "name": "'
  31. $client2 = '",
  32.         "address": "'
  33. $client3 = '",
  34.         "subscriptions": [ "none" ]
  35.     }
  36. }'
  37. echo $client1$HOSTNAME$client2$LOCALIP$client3 > "C:\opt\sensu\conf.d\client.json"
  38.  
  39. $CHECK1 = '{
  40.     "checks": {
  41.         "Disk": {
  42.             "command": "check-windows-disk.rb -w 85 -c 95",
  43.             "standalone": true,
  44.             "interval": 120
  45.         },
  46.         "CPU": {
  47.             "command": "check-windows-cpu-load.rb -w 85 -c 95",
  48.             "standalone": true,
  49.             "interval": 60
  50.         },
  51.         "RAM": {
  52.             "command": "check-windows-ram.rb -w 85 -c 95",
  53.             "standalone": true,
  54.             "interval": 60
  55.         },
  56.         "Uptime": {
  57.             "command": "metrics-windows-uptime.rb",
  58.             "standalone": true,
  59.             "interval": 60
  60.         },
  61.         "RDP_Service": {
  62.             "command": "check-windows-service.rb -p '
  63. $SERVICENAME1 = "`'Remote Desktop Services`'"
  64. $CHECK2 = ' -w 300",
  65.             "standalone": true,
  66.             "interval": 60
  67.         }
  68.  
  69.     }
  70. }'
  71. echo $CHECK1$SERVICENAME1$CHECK2 > "C:\opt\sensu\conf.d\check_windows.json"
  72.  
  73. #create and start the service
  74. echo '
  75. <service>
  76.  <id>sensu-client</id>
  77.  <name>Sensu Client</name>
  78.  <description>This service runs a Sensu client</description>
  79.  <executable>C:\opt\sensu\embedded\bin\ruby</executable>
  80.  <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>
  81. </service>
  82. ' > "C:\opt\sensu\bin\sensu-client.xml"
  83. sc create sensu-client start= delayed-auto binPath= c:\opt\sensu\bin\sensu-client.exe DisplayName= "Sensu Client"
  84. sc sensu-client start
Advertisement
Add Comment
Please, Sign In to add comment