Newer
Older
package fetch
import (
"fmt"
"log"
"crypto/tls"
"encoding/json"
"net/http"
)
var Hosts = map[string]Host{}
const apiurl = "https://chapman.lysator.liu.se/api/"
// which classes a given host has
var hostClasses map[float64][]Puppetclass
// password for foreman access, TODO replace with API key
// echo curl --user "hugo:$(pass lysator/hugo)" -k https://chapman.lysator.liu.se/api/hosts
hostClasses = map[float64][]Puppetclass{}
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
for _, record := range m.Results {
Hosts[record.Name] = Host{record}
}
fff("puppetclasses", &m2)
for group, entries := range m2.Results {
log.Print("Handling ", group)
for _, entry := range entries {
// e := entry.(map[string]interface{})
AllClasses[entry.Name] = entry
}
}
}
func fff (url string, message interface{}) {
request, err := http.NewRequest("GET", apiurl + url, nil)
resp, err := client.Do(request)
if err != nil {
}
func fff_pages(url string, message IsMessage) {
fff(url, &message)
log.Printf("message = %+v", message.GetMessage())
// TODO
// logic here for fetching additional pages
// (preferably async)
// IsMessage should require a Merge method
// TODO also figure out pointer stuff
if val, ok := hostClasses[host.Id]; ok {
for _, values := range m.Results {
record = append(record, values...)
}
hostClasses[host.Id] = record
str = append(str, r.Name)
}
return str
}
Ip string // "130.236.254.139",
Ip6 string // "2001:6b0:17:f0a0::8b",
Environment_id float64 // 1,
Environment_name string // "production",
Last_report string // "2020-10-28 19:10:57 UTC",
Mac string // "1c:c1:de:03:e7:b6",
"realm_id": null,
"realm_name": null,
"sp_mac": null,
"sp_ip": null,
"sp_name": null,
Domain_id float64 // 1,
Domain_name string // "lysator.liu.se",
Architecture_id float64 // 1,
Architecture_name string // "x86_64",
Operatingsystem_id float64 // 6,
Operatingsystem_name string // "CentOS Linux 7.8.2003",
"subnet_id": null,
"subnet_name": null,
"subnet6_id": null,
"subnet6_name": null,
"sp_subnet_id": null,
"ptable_id": null,
"ptable_name": null,
"medium_id": null,
"medium_name": null,
"pxe_loader": null,
"build": false,
Owner_id float64 // 5,
Owner_name string // "Henrik Henriksson",
Owner_type string // "User",
Enabled bool // true,
Managed bool // false,
"uuid": null,
"compute_resource_id": null,
"compute_resource_name": null,
"compute_profile_id": null,
"compute_profile_name": null,
*/
// capabilities []interface{} // [ "build" ],
Provision_method string // "build",
*/
Created_at string // "2020-08-16 19:51:59 UTC",
Updated_at string // "2020-10-28 19:11:26 UTC",
/*
Global_status float64 // 0,
Global_status_label string // "OK",
Uptime_seconds float64 // 20857465,
Organization_id float64 // 1,
Organization_name string // "Lysator",
Location_id float64 // 2,
Location_name string // "Foo",
Puppet_status float64 // 0,
Model_name string // "ProLiant DL180 G6",
Configuration_status float64 // 0,
Configuration_status_label string // "No changes",
Name string // "analysator-system.lysator.liu.se",
Id float64 // 13,
Puppet_proxy_id float64 // 1,
Puppet_proxy_name string // "chapman.lysator.liu.se",
Puppet_ca_proxy_id float64 // 1,
Puppet_ca_proxy_name string // "chapman.lysator.liu.se",
"puppet_proxy": {
"name": "chapman.lysator.liu.se",
"id": 1,
"url": "https://chapman.lysator.liu.se:8443"
},
"puppet_ca_proxy": {
"name": "chapman.lysator.liu.se",
"id": 1,
"url": "https://chapman.lysator.liu.se:8443"
},
Hostgroup_title string // "Analysator/System"
}
type IsMessage interface {
GetMessage() Message
// TODO
// MergeMessage(Message) Message
}
// search
// sort { by, order null }
}
type HostMessage struct {
Message
Results []HostRecord
}
func (m HostMessage) GetMessage() Message {
return m.Message
}
Name string // "profiles::localtime"
Created_at string // "2020-10-27T07:57:47.102Z"
Updated_at string // "2020-10-27T07:57:47.102Z"
func (m PuppetclassMessage) GetMessage() Message {
return m.Message
}