This commit is contained in:
52
main.go
52
main.go
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
_ "time/tzdata"
|
||||
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
goconfluence "github.com/virtomize/confluence-go-api"
|
||||
)
|
||||
|
||||
@@ -176,6 +178,37 @@ func getScsiBusSharingVMs(client *govmomi.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateHtml(htmlContent string, heading string, newTable string) string {
|
||||
// Load the HTML content into a goquery document
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlContent))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return htmlContent
|
||||
}
|
||||
|
||||
// Find the h2 heading that matches our heading passed to the function
|
||||
doc.Find("h2").Each(func(i int, s *goquery.Selection) {
|
||||
if s.Text() == heading {
|
||||
// Find the table that follows this h2 heading
|
||||
table := s.NextFiltered("table")
|
||||
|
||||
// Replace the table with a new table
|
||||
//newTableHTML := "<table><tr><td>New Table Row 1</td></tr></table>"
|
||||
newTable, _ := goquery.NewDocumentFromReader(strings.NewReader(newTable))
|
||||
table.ReplaceWithSelection(newTable.Selection)
|
||||
}
|
||||
})
|
||||
|
||||
h, err := doc.Html()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return htmlContent
|
||||
}
|
||||
|
||||
return h
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Command line flags
|
||||
/*
|
||||
@@ -262,7 +295,24 @@ func main() {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%+v\n", c)
|
||||
//fmt.Printf("%+v\n", c)
|
||||
|
||||
fmt.Printf("Current content: %s\n", c.Body.Storage.Value)
|
||||
|
||||
dummyTable := "<table><tbody><tr><th>VM Name</th><th>Cluster Name</th></tr><tr><td>VM1</td><td>Cluster1</td></tr></tbody></table>"
|
||||
newContent := updateHtml(c.Body.Storage.Value, "wsdc-vc-npr.srv.westpac.com.au", dummyTable)
|
||||
fmt.Printf("newContent: %v\n", newContent)
|
||||
|
||||
/*
|
||||
c.Body.Storage.Value = newContent
|
||||
|
||||
result, err := api.UpdateContent(c)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("result: %v\n", result)
|
||||
*/
|
||||
|
||||
/*
|
||||
err = getScsiBusSharingVMs(c)
|
||||
|
Reference in New Issue
Block a user