Skip to content

Commit

Permalink
Merge branch 'release-0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
William Lam committed Mar 10, 2020
2 parents 535addb + 976adc5 commit 8999291
Show file tree
Hide file tree
Showing 87 changed files with 3,785 additions and 906 deletions.
5 changes: 5 additions & 0 deletions .gitignore
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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Feature requests should fall within the scope of the project.
Before submitting a pull request, please make sure that your change satisfies the following requirements:
- vCenter Event Broker Appliance can be built and deployed. See the getting started build guide [here](getting-started-build.md).
- The change is signed as described by the [Developer Certificate of Origin](https://cla.vmware.com/dco) doc.
- The change is clearly documented
- Contributions to the [examples](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples) contains a titled readme and the title is listed in the [use cases table](https://github.com/vmware-samples/vcenter-event-broker-appliance/blob/master/examples/README.md).
- The change is clearly documented and follows Git commit [best practices](https://chris.beams.io/posts/git-commit/)
- Contributions to the [examples](https://github.com/vmware-samples/vcenter-event-broker-appliance/tree/master/examples) contains a titled readme and the title is listed in the [use cases table](https://github.com/vmware-samples/vcenter-event-broker-appliance/blob/master/examples/README.md).
121 changes: 92 additions & 29 deletions FAQ.md → DESIGN.md

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ Please refer to the getting started guide [here](getting-started.md)

The vCenter Event Broker Appliance follows a highly modular approach, using Kubernetes and containers as an abstraction layer between the base operating system ([Photon OS](https://github.com/vmware/photon)) and the required application services. Currently the following components are used in the appliance:

- Photon OS ([Github](https://github.com/vmware/photon))
- Kubernetes ([Github](https://github.com/kubernetes/kubernetes))
- VMware Event Router ([Github](https://github.com/vmware-samples/vcenter-event-broker-appliance/vmware-event-router))
- Supported Event Stream Sources:
- VMware vCenter ([Website](https://www.vmware.com/products/vcenter-server.html))
- Supported Event Stream Processors:
- OpenFaaS ([Website](https://www.openfaas.com/))
- AWS EventBridge ([Website](https://aws.amazon.com/eventbridge/))
- Contour ([Github](https://github.com/projectcontour/contour))
- OpenFaaS ([Website](https://www.openfaas.com/))
- vCenter Connector ([Github](https://github.com/openfaas-incubator/vcenter-connector/))
- Kubernetes ([Github](https://github.com/kubernetes/kubernetes))
- Photon OS ([Github](https://github.com/vmware/photon))

<center><div style="height:250px;width:250px"><img src="veba-appliance-diagram.png" /></div></center>

For more details about the individual components and how they are used in the vCenter Event Broker Appliance, please see the [architecture page](architecture.md) or [FAQ](FAQ.md).
For more details about the individual components and how they are used in the vCenter Event Broker Appliance, please see the [design page](DESIGN.md).

## Join Conversation

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.0
v0.3.0
43 changes: 0 additions & 43 deletions architecture.md

This file was deleted.

9 changes: 8 additions & 1 deletion examples/README.md
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)| |
91 changes: 91 additions & 0 deletions examples/powercli/datastore-usage-email/README.md
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 examples/powercli/datastore-usage-email/handler/script.ps1
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
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ provider:
name: openfaas
gateway: https://veba.primp-industries.com
functions:
powershell-eventbridge:
powershell-datastore-usage:
lang: powercli
handler: ./handler
image: lamw/powershell-eventbridge:latest
image: vmware/veba-powercli-datastore-notification:latest
environment:
write_debug: true
read_debug: true
function_debug: false
secrets:
- eventbridge-secrets
- vc-datastore-config
annotations:
topic: vm.removed
topic: AlarmStatusChangedEvent
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
Expand Down
11 changes: 11 additions & 0 deletions examples/powercli/datastore-usage-email/vc-datastore-config.json
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]"
}
59 changes: 0 additions & 59 deletions examples/powercli/eventbridge/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions examples/powercli/eventbridge/eventbridge-secrets.json

This file was deleted.

32 changes: 0 additions & 32 deletions examples/powercli/eventbridge/handler/script.ps1

This file was deleted.

Loading

0 comments on commit 8999291

Please sign in to comment.