-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
3,785 additions
and
906 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
packer_cache/ | ||
output-vmware-iso/ | ||
dist/ | ||
.vscode | ||
username | ||
password | ||
secret*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.2.0 | ||
v0.3.0 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
# About the Example Functions | ||
|
||
This page lists ready to use functions curated by the vCenter Event Broker community. They serve as an easy way to use the appliance and as an inspiration for how to write functions in different languages. | ||
|
||
> **Note:** These functions are provided and tested to be used with the vCenter Event Broker Appliance deployed with [OpenFaaS](../DESIGN.md#components) as the event stream processor. | ||
| Use Cases | Python | PowerCLI | | ||
|-----------------|--------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------| | ||
| vSphere Tagging | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples/python/tagging) | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples/powercli/tagging) | | ||
| Send VM Configuration Changes to Slack | | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples/powercli/hwchange-slack) | | ||
| Disable Alarms for Host Maintenance | | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples/powercli/hostmaint-alarms) | | ||
| ESX Maximum transmission unit fixer | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples/python/esx-mtu-fixer) | | | ||
| AWS EventBridge | | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/development/examples/powercli/eventbridge) | | ||
| Datastore Usage Notification | | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples/powercli/datastore-usage-email) | | ||
| Echo VEBA Event | [Link](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples/python/echo)| | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# vSphere Datastore Usage Email Notification | ||
|
||
## Description | ||
|
||
This function demonstrates using PowerShell to send an email notification when warning/error threshold is reach for Datastore Usage Alarm in vSphere | ||
|
||
## Consume Function Instruction | ||
|
||
Step 1 - Clone repo | ||
|
||
``` | ||
git clone https://github.com/vmware-samples/vcenter-event-broker-appliance | ||
cd vcenter-event-broker-appliance/examples/powercli/datastore-usage-email | ||
git checkout master | ||
``` | ||
|
||
Step 2 - Update `stack.yml` and `vc-datastore-config.json` with your environment information | ||
|
||
<B>Note:</B> leave SMTP_USERNAME and SMTP_PASSWORD blank if you do not want to use authenticated SMTP | ||
|
||
Step 3 - Login to the OpenFaaS gateway on vCenter Event Broker Appliance | ||
|
||
``` | ||
VEBA_GATEWAY=https://veba.primp-industries.com | ||
export OPENFAAS_URL=${VEBA_GATEWAY} | ||
faas-cli login --username admin --password-stdin --tls-no-verify | ||
``` | ||
|
||
Step 4 - Create function secret (only required once) | ||
|
||
``` | ||
faas-cli secret create vc-datastore-config --from-file=vc-datastore-config.json --tls-no-verify | ||
``` | ||
|
||
Step 5 - Deploy function to vCenter Event Broker Appliance | ||
|
||
``` | ||
faas-cli deploy -f stack.yml --tls-no-verify | ||
``` | ||
|
||
## Build Function Instruction | ||
|
||
Step 1 - Clone repo | ||
|
||
``` | ||
git clone https://github.com/vmware-samples/vcenter-event-broker-appliance | ||
cd vcenter-event-broker-appliance/examples/powercli/datastore-usage-email | ||
git checkout master | ||
``` | ||
|
||
Step 2 - Initialize function, only required during the first deployment | ||
|
||
``` | ||
faas-cli template pull | ||
``` | ||
|
||
Step 3 - Update `stack.yml` and `vc-datastore-config.json` with your environment information. Please ensure you replace the name of the container image with your own account. | ||
|
||
Step 4 - Build the function container | ||
|
||
``` | ||
faas-cli build -f stack.yml | ||
``` | ||
|
||
Step 5 - Push the function container to Docker Registry (default but can be changed to internal registry) | ||
|
||
``` | ||
faas-cli push -f stack.yml | ||
``` | ||
|
||
Step 6 - Login to the OpenFaaS gateway on vCenter Event Broker Appliance | ||
|
||
``` | ||
VEBA_GATEWAY=https://veba.primp-industries.com | ||
export OPENFAAS_URL=${VEBA_GATEWAY} | ||
faas-cli login --username admin --password-stdin --tls-no-verify | ||
``` | ||
|
||
Step 7 - Create function secret (only required once) | ||
|
||
``` | ||
faas-cli secret create vc-datastore-config --from-file=vc-datastore-config.json --tls-no-verify | ||
``` | ||
|
||
Step 8 - Deploy function to vCenter Event Broker Appliance | ||
|
||
``` | ||
faas-cli deploy -f stack.yml --tls-no-verify | ||
``` |
60 changes: 60 additions & 0 deletions
60
examples/powercli/datastore-usage-email/handler/script.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Process function Secrets passed in | ||
$VC_CONFIG_FILE = "/var/openfaas/secrets/vc-datastore-config" | ||
$VC_CONFIG = (Get-Content -Raw -Path $VC_CONFIG_FILE | ConvertFrom-Json) | ||
if($env:function_debug -eq "true") { | ||
Write-host "DEBUG: `"$VC_CONFIG`"" | ||
} | ||
|
||
# Process payload sent from vCenter Server Event | ||
$json = $args | ConvertFrom-Json | ||
if($env:function_debug -eq "true") { | ||
Write-Host "DEBUG: json=`"$($json | Format-List | Out-String)`"" | ||
} | ||
|
||
$alarmName = ($json.data.alarm.name -replace "\n"," ") | ||
$datastoreName = $json.data.ds.name | ||
$alarmStatus = $json.data.to | ||
$vcenter = ($json.source -replace "/sdk","") | ||
$datacenter = $json.data.datacenter.name | ||
|
||
if($env:function_debug -eq "true") { | ||
Write-Host "DEBUG: alarmName: `"$alarmName`"" | ||
Write-host "DEBUG: datastoreName: `"$datastoreName`"" | ||
Write-Host "DEBUG: alarmStatus: `"$alarmStatus`"" | ||
Write-Host "DEBUG: vcenter: `"$vcenter`"" | ||
} | ||
|
||
if( ("$alarmName" -match "$($VC_CONFIG.VC_ALARM_NAME)") -and ([bool]($VC_CONFIG.DATASTORE_NAMES -match "$datastoreName")) -and ($alarmStatus -eq "yellow" -or $alarmStatus -eq "red" -or $alarmStatus -eq "green") ) { | ||
|
||
# Warning Email Body | ||
if($alarmStatus -eq "yellow") { | ||
$subject = "⚠️ $($VC_CONFIG.EMAIL_SUBJECT) ⚠️ " | ||
$threshold = "warning" | ||
} elseif($alarmStatus -eq "red") { | ||
$subject = "☢️ $($VC_CONFIG.EMAIL_SUBJECT) ☢️ " | ||
$threshold = "error" | ||
} elseif($alarmStatus -eq "green") { | ||
$subject = "$($VC_CONFIG.EMAIL_SUBJECT)" | ||
$threshold = "normal" | ||
} | ||
|
||
$Body = "$alarmName $datastoreName has reached $threshold threshold.`r`n" | ||
|
||
if ( $threshold -ne "normal" ) { | ||
$Body = $Body + "Please log in to your VMware Cloud on AWS environment and ensure that everything is operating as expected.`r`n" | ||
} | ||
|
||
$Body = $Body + @" | ||
vCenter Server: $vcenter | ||
Datacenter: $datacenter | ||
Datastore: $datastoreName | ||
"@ | ||
if ($VC_CONFIG.SMTP_PASSWORD.length -gt 0 -and $VC_CONFIG.SMTP_USERNAME.length -gt 0) { | ||
$password = ConvertTo-SecureString "$($VC_CONFIG.SMTP_PASSWORD)" -AsPlainText -Force | ||
$credential = New-Object System.Management.Automation.PSCredential($($VC_CONFIG.SMTP_USERNAME), $password) | ||
Send-MailMessage -From $($VC_CONFIG.EMAIL_FROM) -to $($VC_CONFIG.EMAIL_TO) -Subject $Subject -Body $Body -SmtpServer $($VC_CONFIG.SMTP_SERVER) -port $($VC_CONFIG.SMTP_PORT) -UseSsl -Credential $credential -Encoding UTF32 | ||
} else { | ||
Send-MailMessage -From $($VC_CONFIG.EMAIL_FROM) -to $($VC_CONFIG.EMAIL_TO) -Subject $Subject -Body $Body -SmtpServer $($VC_CONFIG.SMTP_SERVER) -port $($VC_CONFIG.SMTP_PORT) -Encoding UTF32 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../eventbridge/template/powercli/Dockerfile → ...-usage-email/template/powercli/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM lamw/powercli-eventbridge | ||
FROM vmware/powerclicore:latest | ||
|
||
RUN mkdir -p /home/app | ||
USER root | ||
|
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
examples/powercli/datastore-usage-email/vc-datastore-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"VC_ALARM_NAME" : "Datastore usage on disk", | ||
"DATASTORE_NAMES" : ["e200-8d-local-datastore", "datastore1", "WorkloadDatastore"], | ||
"SMTP_SERVER" : "smtp.gmail.com", | ||
"SMTP_PORT" : "587", | ||
"SMTP_USERNAME" : "[email protected]", | ||
"SMTP_PASSWORD" : "FILE-ME-IN-PLEASE", | ||
"EMAIL_SUBJECT" : "[VMC Datastore Notification Alarm]", | ||
"EMAIL_TO": ["[email protected]"], | ||
"EMAIL_FROM" : "[email protected]" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.