Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### ALARM TRIGGER SCRIPT
  2.  
  3. write-host starting script
  4. install-Module Microsoft.PowerShell.IoT
  5.  
  6. "Set Alarm For Powerup"
  7.  
  8. set-gpiopin -id 3 -value High
  9. sleep 2
  10. set-gpiopin -id 3 -value Low
  11.  
  12. function post-gmmessage {
  13.  
  14. param([string]$text)
  15.  
  16.     $text = $text.replace(" ","+")
  17.     $posturl = 'https://api.groupme.com/v3/bots/post?bot\_id=<OUR\_BOT\_ID>'
  18.     $posturladd = $posturl + $text
  19.     $outnullvar = Invoke-WebRequest -Uri $posturl$text -Method Post
  20.  
  21. }
  22.  
  23.  
  24. function get-gmmessage {
  25.  
  26.     $apiKey = "?token=<OUR\_SECURITY\_TOKEN>"
  27.     $resource = "https://api.groupme.com/v3/groups/<OUR\_GROUP\_ID>"
  28.     $var = Invoke-RestMethod -Uri $resource$apikey
  29.     $var.response.messages.preview.text
  30.  
  31. }
  32.  
  33.  
  34. "Variables Collected"
  35.  
  36. DO {
  37.  
  38.     "Collecting Messages"
  39.     $cmessage = get-gmmessage
  40.     if ( $cmessage -eq "#EXIT" ) { EXIT }
  41.     if ( $cmessage -like "*#911*" ) {
  42.         $cmessage = $cmessage.replace("#","")
  43.         $post = "Confirm Dispatch Alarm at Station $cmessage"
  44.        
  45.         "Dispatch"
  46.         post-gmmessage -text $post
  47.  
  48.         "Pin Set ALARM"
  49.         set-gpiopin -id 3 -value High
  50.         sleep 2
  51.         set-gpiopin -id 3 -value Low
  52.         sleep 8
  53.         set-gpiopin -id 3 -value High
  54.         sleep 2
  55.         set-gpiopin -id 3 -value Low
  56.        
  57.         "Alarm Silence"
  58.        
  59.         "Waiting for message change from current"
  60.    
  61.     }
  62.  
  63.     "Neutral State"
  64.    
  65.     sleep 10
  66.     $failsafe = (Get-Date -Format yyMMddHHmm).ToString()
  67.     $failsafe | Set-Content /<FOLDER>/failsafe.log -Encoding ascii
  68.  
  69. } until ( $never -eq $true )
  70.  
  71.  
  72. ### ALARM TRIGGER SCRIPT END
  73.  
  74.  
  75.  
  76. ### Event EMail
  77.  
  78. "Starting"
  79.  
  80. function send-gmail {
  81.  
  82.     param([string]$subject)
  83.    
  84.     $password = "<mypassword>" | ConvertTo-SecureString -asPlainText -Force
  85.     $username = "<myemail>@gmail.com"
  86.     $credential = New-Object System.Management.Automation.PSCredential($username,$password)
  87.     $From = ["](mailto:"kd0jar@gmail.com)<myemail>@gmail.com"
  88.    $To = ["](mailto:"kd0jar@gmail.com)<myemail>@gmail.com"
  89.     $Body = "Automated Message"
  90.     $SMTPServer = "smtp.gmail.com"
  91.     $SMTPPort = "587"
  92.     Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential ($credential)
  93.  
  94. }
  95.  
  96.  
  97. sleep 10
  98.  
  99. if (( Test-Connection -Count 1 -ComputerName <ourwebsite> -Quiet) -eq $true ) {send-gmail -subject "Startup Detected"}
  100. $count = 0
  101. $success = 0
  102.  
  103. do {
  104.  
  105.     if( (Test-Connection -Count 1 -ComputerName <ourwebsite> -Quiet) -eq $false ) {
  106.         $count = $count + 1
  107.         $success = 0
  108.  
  109.     } elseif (( Test-Connection -Count 1 -ComputerName <ourwebsite> -Quiet) -eq $true ) {
  110.  
  111.         if ( $count -gt 100 ) { send-gmail -subject "$count failed ping on connection re-established" }
  112.         $count = 0
  113.     }
  114.  
  115.     if ( $count -gt 1000 ) { Restart-Computer -Force }
  116.     if ( $success -gt 10000 ) { send-gmail -subject "Still going strong 10k" ; $success = 0 }
  117.     $success = $success + 1
  118.     $failsafe = (Get-Date -Format yyMMddHHmm).ToString()
  119.     $failsafecheck = Get-Content /<FOLDER>/failsafe.log
  120.     if ( ( $failsafe - 10 ) -gt $failsafecheck ) { send-gmail -subject "Runscript stopped running" ; Restart-Computer -Force }
  121.     sleep 5
  122.  
  123. } until ( $never -eq $true )
  124.  
  125. ### Event EMail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement