Skip to content

Instantly share code, notes, and snippets.

View embano1's full-sized avatar

Michael Gasch embano1

View GitHub Profile
@embano1
embano1 / main.go
Created April 2, 2020 18:56
Playing with stateFn and a stupid counter
// inspired by
// https://github.com/golang/go/blob/8d7be1e3c9a98191f8c900087025c5e78b73d962/src/text/template/parse/lex.go#L228
package main
import (
"fmt"
"log"
)
type stateFn func(s *state) stateFn
package main
import "sync"
type MetricEnum int
type Metric struct {
Value float64
}
@embano1
embano1 / ce-xml.md
Created February 4, 2021 08:56
CloudEvents XML pretty print representation
# DrsPoweredOnEvent
{'attributes': {'specversion': '1.0', 'id': '8583', 'source': '10.161.153.226', 'type': 'com.vmware.vsphere.DrsVmPoweredOnEvent', 'datacontenttype': 'application/xml', 'time': '2021-02-04T08:53:57.182999Z', 'eventclass': 'event'}, 'data': b'<DrsVmPoweredOnEvent><key>8583</key><chainId>8577</chainId><createdTime>2021-02-04T08:53:57.182999Z</createdTime><userName>VSPHERE.LOCAL\\Administrator</userName><datacenter><name>vcqaDC</name><datacenter type="Datacenter">datacenter-2</datacenter></datacenter><computeResource><name>cls</name><computeResource type="ClusterComputeResource">domain-c7</computeResource></computeResource><host><name>10.161.139.167</name><host type="HostSystem">host-27</host></host><vm><name>test-01</name><vm type="VirtualMachine">vm-56</vm></vm><fullFormattedMessage>DRS powered On test-01 on 10.161.139.167 in vcqaDC</fullFormattedMessage><template>false</template></DrsVmPoweredOnEvent>'}
# EventEx
{'attributes': {'specversion': '1.0', 'id': '8574', 'sour
@embano1
embano1 / Dockerfile
Created March 8, 2021 09:32
Dockerfile scratch for vcsim and govc
# golang:1.16.0-buster amd64
FROM golang@sha256:f254180c5defa2653955e963fb0626e3d4fbbb162f7cff6490e94607d1d867ff AS builder
WORKDIR /src
COPY go.mod .
COPY go.sum .
RUN go mod download
RUN groupadd -g 61000 vcsim
RUN useradd -g 61000 -l -m -s /bin/false -u 61000 vcsim

Example vSphere Alarm events sent from VMware Event Router and enriched with the vSphere Alarm Server

AlarmStatusChangedEvent Datastore Disk Usage

Configuration rule in UI: "IF Datastore Disk Usage IS ABOVE 5% TRIGGER THE ALARM AND Show as Warning"

Metadata

id:
@embano1
embano1 / README.md
Created April 15, 2021 07:47
Examples: gh api

Delete all runs for a given workflow

# get and verify runs by last run time
# workflow ID can be replaced with file name
gh api -q '.workflow_runs[].created_at' /repos/:owner/:repo/actions/workflows/govmomi-tests.yaml/runs

# delete them
gh api -q '.workflow_runs[].id' /repos/:owner/:repo/actions/workflows/govmomi-tests.yaml/runs | xargs -I {} gh api -X DELETE /repos/:owner/:repo/actions/runs/{}
@embano1
embano1 / README.md
Created April 15, 2021 15:51
Delete git tags locally/remote
# delete all tags on remote
git tag -l | xargs -I {} git push origin :refs/tags/{}

# delete all tags locally
git tag -l | xargs git tag -d
@embano1
embano1 / all-in-one.yaml
Last active April 16, 2021 20:08
Knative Trigger to Sequence to Parallel
# Trigger which fires off to a sequence
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: alarmsequence-trigger
spec:
broker: default
subscriber:
ref:
apiVersion: flows.knative.dev/v1
@embano1
embano1 / README.md
Last active April 20, 2021 13:40
List and disable Github Actions in accessible Github Repositories

⚠️ !!!WARNING!!! ⚠️

Use at your own risk and verify your input/output before performing any (potentially destructive) call against the Github API.

Retrieve Github Repositories

⚠️ These commands assume a working gh CLI environment, i.e. authenticated with at least repo-level permissions (see docs).

Retrieve accessible Github Repositories:

@embano1
embano1 / README.md
Last active May 3, 2021 09:01
Run govmomi events example

Requirements

  • Access to vCenter (network connection, account to read events)
  • git (to clone the repository)
  • go +v1.13 (to build the example binary)

Steps

Check out the repository