package asaModels import ( "regexp" "strings" ) var ( BOOTSYSRE = regexp.MustCompile(`(?i)boot[ ]+system[ ]+(\S+)`) bootVarRe = regexp.MustCompile(`(?i)\nboot\s+variable\s+=\s+(\S+)\n`) currentBootVarRe = regexp.MustCompile(`(?i)current\s+boot\s+variable\s+=\s+(\S+)\n`) configFileRe = regexp.MustCompile(`(?i)config_file\s+variable\s+=\s*(\S+)\n`) currentConfigFileRe = regexp.MustCompile(`(?i)current\s+config_file\s+variable\s+=\s*(\S+)\n`) ) type ( BootSystem struct { BootFiles []*BootFiles `json:"boot_system_list"` } BootFiles struct { BootOrder int `json:"boot_order"` DiskImage string `json:"disk_image"` } // BootVar type defines a list of strings for each config or // boot item set from the `show bootvar` ASA command. BootVar struct { BootVar []string `json:"boot_variable"` CurrentBootVar []string `json:"current_boot_variable"` ConfigFile []string `json:"config_file"` CurrentConfigFile []string `json:"current_config_file"` } ) func (b *BootSystem) Parse(s string) { for k, v := range BOOTSYSRE.FindAllStringSubmatch(s, -1) { b.BootFiles = append(b.BootFiles, &BootFiles{ BootOrder: k, DiskImage: v[1], }) } } func FindBootImage(i int, files []*BootFiles) *string { for _, f := range files { if f.BootOrder == i { return &f.DiskImage } } return nil } func FindBootFile(fn string, files []*BootFiles) (bool, int) { for i, f := range files { if f.DiskImage == fn { return true, i } } return false, 0 } // ParseBootVar function will take output from the `show bootvar` command on an // ASA and parse the data into a type of BootVar func ParseBootVar(s string) (bv BootVar) { if res := bootVarRe.FindStringSubmatch(s); res != nil { bv.BootVar = strings.Split(res[1], ";") } if res := currentBootVarRe.FindStringSubmatch(s); res != nil { bv.CurrentBootVar = strings.Split(res[1], ";") } if res := configFileRe.FindStringSubmatch(s); res != nil { bv.ConfigFile = strings.Split(res[1], ";") } if res := currentConfigFileRe.FindStringSubmatch(s); res != nil { bv.CurrentConfigFile = strings.Split(res[1], ";") } return }