Simons Roliga Kod
From Datateknik
(Difference between revisions)
(→Övervakning via Linux) |
(→Övervakning via Linux) |
||
Line 122: | Line 122: | ||
<div class="mw-collapsible-content"> | <div class="mw-collapsible-content"> | ||
https://medium.com/better-programming/how-to-send-push-notifications-to-your-phone-from-any-script-6b70e34748f6 | https://medium.com/better-programming/how-to-send-push-notifications-to-your-phone-from-any-script-6b70e34748f6 | ||
+ | |||
+ | * Visit http://ifttt.com and sign up for an account. | ||
+ | * Click on your account icon (top right), and then click on Create. | ||
+ | * Click on the If+ icon and type “Webhooks” in the search box. | ||
+ | * Select Webhooks → Receive a Web Request and type “notify” for your event name. | ||
+ | * Next, click on the +That icon and type “Notifications” in the search box. | ||
+ | * Select “Send a notification from the IFTTT app.” | ||
+ | * Type the following text into the Message box: | ||
+ | Notification: {{Value1}} | ||
+ | * Click 'Create action' and then give your action a name, e.g. “Push Notification.” Then click on Finish. | ||
curl -X POST -H "Content-Type: application/json" -d '{"value1":"Warning: Host 193.10.203.12 is DOWN!"}' https://maker.ifttt.com/trigger/notify/with/key/DIN_API_NYCKEL_HÄR | curl -X POST -H "Content-Type: application/json" -d '{"value1":"Warning: Host 193.10.203.12 is DOWN!"}' https://maker.ifttt.com/trigger/notify/with/key/DIN_API_NYCKEL_HÄR | ||
</div></div> | </div></div> |
Revision as of 19:48, 21 September 2020
Contents |
Mediawiki
Expanderbar text, typ folds
<div class="toccolours mw-collapsible mw-collapsed"> This text is not collapsible; but the next is collapsible and hidden by default: <div class="mw-collapsible-content">Text to be expanded/hidden</div> </div>
Bash
Testa om en viss port är öppen på en lista hostar
#This is a bash script to check ssh services on hosts #You need a host file with each IP-address on a separate row #The source file for the text is used as an argument, ie ./ssh-check.sh ip.txt #Edit the nc row to alter the port you are testing for, in this case its ssh=22 #Results are output to screen and a text file in the same directory #!/bin/bash echo "==================================" rm results.txt while read p; do nc -znv -w3 $p 22 if [ $? -ne 0 ] then echo "No connection" | tee -a results.txt else echo "OK" | tee -a results.txt fi done < $1
Genererar QR koder från en lista
# This is a bash script to generate qrcodes by reading a text string # from a file and adding a human readable text part below the qr code # The source file for the text is used as an argument, ie ./qrcodes.sh hosts.txt #!/bin/bash echo "==================================" while read p; do if echo "$p" | grep '*\|\/'; then echo "Illegal entry in hosts.txt file" break else qrencode -s 5 -i $p -o $p-QR.png convert $p-QR.png -pointsize 24 label:"$p" -gravity center -append $p.png rm $p-QR.png fi done < $1
PowerCLI för VMware (körs i Powershell! - spara som powershell skript...)
För att skapa en mängd VLANS utan att sitta manuellt i Vcentret (obs PowerCLI är farligt!)
// 1. behövs för att köra vm-ware modulen i windows då den är "tredjepart" Set-ExecutionPolicy remotesigned // 2. -Scope begränsar installation till inloggad användare install-module -Name VMware.PowerCLI -Scope CurrentUser // 3. Kommer att fråga om dina credentials, använd samma som gui inloggningen Connect-VIServer -server vcenter-b.cnap.hv.se // 4. länk till object som är h6 hosten (till exempel) $myVMHost = Get-VMHost -name esxi-h6.cnap.hv.se !! VA RIKTIGT RIKTIGT SÄKER PÅ ATT DET ÄR HÄR DU VILL PILLA !! // 5. länk till vswitch som skall pillas på $vswitch = Get-VirtualSwitch -vmhost $myVMHost -name vSwitch1 // 6. Skapar VLAN med namn "VLAN20XX" och vlan id 20XX for ($i=2004; $i -le 2038; $i++) {New-VirtualPortGroup -VirtualSwitch $vswitch -name "VLAN$i" -VLanId $i} // 7. tar bort portgroups "VLAN2037-VLAN2038" på vswitchen som definieras i steg >>5<< // OBS! -confirm:$false stänger av en "are you sure, dummy" fråga. Är du inte säker, ta bort detta ur raden! OBS! for ($i=2037; $i -le 2038; $i++) {Get-VirtualPortGroup -VirtualSwitch $vswitch -name "VLAN$i" | Remove-VirtualPortGroup -confirm:$false} // Bryt kopplingen till vcentret Disconnect-VIServer
Taget från virtuallymikebrown.com
Mass-radera VMs som matchar en sträng | Obs: anslut till rätt host också först (steg 1-4) ovan
$remove_vms = Read-Host -Prompt 'Input the server match string to remove from disk' Write-Host "The entered string was: '$remove_vms'" $select_confirm = Read-Host -Prompt 'Confirm your selection string (y/n)' if($select_confirm -eq 'y') { $VMs = Get-VM $remove_vms foreach($VM in $VMs) { Write-Host $VM } Write-Host "The listed VMs above will be permanently deleted from disk!" Write-Host "Are you absolutely sure you want to do this?" $nuclearoption = Read-Host -Prompt 'Type in "DELETE" to confirm this operation!' if($nuclearoption -eq 'DELETE') { Write-Host "Deleting..." foreach($active in $VMs) { if($active.Powerstate -eq "PoweredOn") { Stop-VM -VM $active -Confirm:$false -RunAsync | Out-Null Start-Sleep -Seconds 7 } } foreach($delete in $VMs) { Remove-VM -VM $delete -DeleteFromDisk -Confirm:$false -RunAsync | Out-Null } } }
Övervakning via Linux
För att skicka notifieringar till Android telefon (appen heter IFTTT - kommandos pushas via curl)
- Visit http://ifttt.com and sign up for an account.
- Click on your account icon (top right), and then click on Create.
- Click on the If+ icon and type “Webhooks” in the search box.
- Select Webhooks → Receive a Web Request and type “notify” for your event name.
- Next, click on the +That icon and type “Notifications” in the search box.
- Select “Send a notification from the IFTTT app.”
- Type the following text into the Message box:
Notification: Template:Value1
- Click 'Create action' and then give your action a name, e.g. “Push Notification.” Then click on Finish.
curl -X POST -H "Content-Type: application/json" -d '{"value1":"Warning: Host 193.10.203.12 is DOWN!"}' https://maker.ifttt.com/trigger/notify/with/key/DIN_API_NYCKEL_HÄR