package pkg import ( "regexp" "strings" "github.rackspace.com/gorax/tools/util" ) var ( HOSTNAMERE = regexp.MustCompile(`(?i)hostname\s+(\S+)`) ) type ( SysUcs struct { UcsList []string `json:"ucs"` } SysNtp struct { Servers []string `json:"servers"` TimeZone string `json:"timezone"` } SysSsh struct { Banner bool `json:"banner_enabled"` BannerTxt string `json:"banner-text"` } SysSyslog struct { RemoteServers []*SyslogRmt `json:"remote-servers"` } SyslogRmt struct { Name string `json:"name"` Host string `json:"host"` } SysGlobalSettings struct { GuiSecBanner string `json:"gui_security_banner_text"` GuiSetup string `json:"gui_setup"` PasswordPrompt string `json:"password_prompt"` UsernamePrompt string `json:"username_prompt"` HostName string `json:"host_name"` } ) func (u *SysUcs) Parse(s string) { u.UcsList = strings.Split(s, "\n") } func (n *SysNtp) Parse(s string) { n.Servers = strings.Split(util.RegexpString(regexp.MustCompile(`(?i)servers\s+\{\s+(.*?)\s+}`), s), " ") n.TimeZone = util.RegexpString(regexp.MustCompile(`(?i)timezone\s+(\S+)`), s) } func (b *SysSsh) Parse(s string) { b.Banner = regexp.MustCompile(`(?i)banner\s+(enabled)`).MatchString(s) b.BannerTxt = util.RegexpString(regexp.MustCompile(`(?i)banner-text\s+(".*?"|\S+)`), s) } func (b *SysSyslog) Parse(s string) { for _, i := range util.BraceParse(util.RegexpFindString(regexp.MustCompile(`(?i)sys\s+syslog\s+\{\n\s+remote-servers\s+\{\n\s+((.|\n)*?)$`), s)) { b.RemoteServers = append(b.RemoteServers, &SyslogRmt{ Name: util.RegexpString(regexp.MustCompile(`(\S+)\s+\{`), i), Host: util.RegexpString(regexp.MustCompile(`host\s+(\S+)`), i), }) } } func (g *SysGlobalSettings) Parse(s string) { g.GuiSecBanner = util.RegexpString(regexp.MustCompile(`(?i)gui-security-banner-text\s+(".*?"|\S+)`), s) g.GuiSetup = util.RegexpString(regexp.MustCompile(`(?i)gui-setup\s+(\S+)`), s) g.PasswordPrompt = util.RegexpString(regexp.MustCompile(`(?i)password-prompt\s+(".*?"|\S+)`), s) g.UsernamePrompt = util.RegexpString(regexp.MustCompile(`(?i)username-prompt\s+(".*?"|\S+)`), s) g.HostName = util.RegexpString(HOSTNAMERE, s) }