test accessing confluence
This commit is contained in:
5
go.mod
5
go.mod
@@ -3,3 +3,8 @@ module nathan/vm-report-confluence/v2
|
||||
go 1.21.0
|
||||
|
||||
require github.com/vmware/govmomi v0.32.0
|
||||
|
||||
require (
|
||||
github.com/magefile/mage v1.14.0 // indirect
|
||||
github.com/virtomize/confluence-go-api v1.4.6 // indirect
|
||||
)
|
||||
|
7
go.sum
7
go.sum
@@ -1,13 +1,20 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
|
||||
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/virtomize/confluence-go-api v1.4.6 h1:yN1khm2tU0aFc7N7x58QQ+668rko77qIMIhs2f+qEO8=
|
||||
github.com/virtomize/confluence-go-api v1.4.6/go.mod h1:a96WPcok5g+7l5LC/ztcrp4cLmrIA1DHxxZSv/iqvsQ=
|
||||
github.com/vmware/govmomi v0.32.0 h1:Rsdi/HAX5Ebf9Byp/FvBir4sfM7yP5DBUeRlbC6vLBo=
|
||||
github.com/vmware/govmomi v0.32.0/go.mod h1:JA63Pg0SgQcSjk+LuPzjh3rJdcWBo/ZNCIwbb1qf2/0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
92
main.go
92
main.go
@@ -2,14 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
_ "time/tzdata"
|
||||
|
||||
@@ -18,6 +15,8 @@ import (
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
|
||||
goconfluence "github.com/virtomize/confluence-go-api"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -133,7 +132,7 @@ func getScsiBusSharingVMs(client *govmomi.Client) error {
|
||||
fmt.Printf("owner: %v\n", owner)
|
||||
*/
|
||||
|
||||
// Determine cluster based on runtime host of VM
|
||||
// Determine cluster based on runtime host of VM based on https://github.com/vmware/govmomi/issues/1242#issuecomment-427671990
|
||||
for _, host := range hsList {
|
||||
if host.Reference() == *vm.Summary.Runtime.Host {
|
||||
fmt.Printf("host %s matches with parent %s\n", host.Name, host.Parent)
|
||||
@@ -156,9 +155,9 @@ func getScsiBusSharingVMs(client *govmomi.Client) error {
|
||||
fmt.Printf("scsi: %v\n", scsi)
|
||||
controller := scsi.GetVirtualSCSIController()
|
||||
//fmt.Printf("controller: %s\n", device.GetVirtualDevice().DeviceInfo.GetDescription().Label)
|
||||
if controller.SharedBus != "noSharing" {
|
||||
fmt.Printf("VM %s is using SCSI bus sharing mode: %s\n", vm.Name, controller.SharedBus)
|
||||
fmt.Printf("VM %s is using SCSI bus sharing mode: %s\n", vm.Name, string(controller.SharedBus))
|
||||
|
||||
if controller.SharedBus != "noSharing" {
|
||||
result := BusSharingResults{
|
||||
VmName: vm.Name,
|
||||
ClusterName: clusterName,
|
||||
@@ -184,6 +183,10 @@ func main() {
|
||||
vPass := flag.String("password", "", "The password to use when connecting to vCenter")
|
||||
vTZ := flag.String("tz", "Australia/Sydney", "The timezone to use when converting vCenter UTC times")
|
||||
vInsecure := flag.Bool("insecure", true, "Allow insecure connections to vCenter")
|
||||
|
||||
cURL := flag.String("confluence-url", "https://confluence.yourdomain.com/wiki/rest/api", "The URL to your confluence rest API endpoint")
|
||||
cToken := flag.String("confluence-token", "", "Your Confluence Personal Access Token")
|
||||
cPageId := flag.String("confluence-pageid", "", "The page ID to update with the report")
|
||||
//vmName := flag.String("vmname", "example-vm", "The vm to query metrics")
|
||||
//begin := flag.Duration("b", time.Hour, "Begin time") // default BeginTime is 1h ago
|
||||
flag.Parse()
|
||||
@@ -205,43 +208,62 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "Error setting timezone to %s : %s\n", *vTZ, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
u, err := url.Parse(*vURL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing url %s : %s\n", *vURL, err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
if !strings.HasSuffix(u.Path, "/sdk") {
|
||||
u.Path, _ = url.JoinPath(u.Path, "/sdk")
|
||||
log.Printf("Updated vCenter URL to '%v'\n", u)
|
||||
/*
|
||||
u, err := url.Parse(*vURL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing url %s : %s\n", *vURL, err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
if !strings.HasSuffix(u.Path, "/sdk") {
|
||||
u.Path, _ = url.JoinPath(u.Path, "/sdk")
|
||||
log.Printf("Updated vCenter URL to '%v'\n", u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Connecting to vCenter %s\n", u)
|
||||
u.User = url.UserPassword(*vUser, *vPass)
|
||||
log.Printf("Connecting to vCenter %s\n", u)
|
||||
u.User = url.UserPassword(*vUser, *vPass)
|
||||
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Login to vcenter
|
||||
c, err = govmomi.NewClient(ctx, u, *vInsecure)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Logging in error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer c.Logout(ctx)
|
||||
*/
|
||||
|
||||
api, err := goconfluence.NewAPI(*cURL, "", *cToken)
|
||||
|
||||
// Login to vcenter
|
||||
c, err = govmomi.NewClient(ctx, u, *vInsecure)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Logging in error: %s\n", err)
|
||||
os.Exit(1)
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer c.Logout(ctx)
|
||||
|
||||
err = getScsiBusSharingVMs(c)
|
||||
// get content by content id
|
||||
c, err := api.GetContentByID(*cPageId, goconfluence.ContentQuery{
|
||||
SpaceKey: "HCS",
|
||||
Expand: []string{"body.storage", "version"},
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error retrieving list of VMs with SCSI Bus Sharing : %s\n", err)
|
||||
return
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%+v\n", c)
|
||||
|
||||
// Output final results in JSON
|
||||
if len(busSharingResults) > 0 {
|
||||
j, _ := json.Marshal(busSharingResults)
|
||||
fmt.Println(string(j))
|
||||
} else {
|
||||
fmt.Println("{}")
|
||||
}
|
||||
/*
|
||||
err = getScsiBusSharingVMs(c)
|
||||
if err != nil {
|
||||
log.Printf("Error retrieving list of VMs with SCSI Bus Sharing : %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Output final results in JSON
|
||||
if len(busSharingResults) > 0 {
|
||||
j, _ := json.Marshal(busSharingResults)
|
||||
fmt.Println(string(j))
|
||||
} else {
|
||||
fmt.Println("{}")
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user