diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2020-02-03 20:18:29 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2020-02-03 20:18:29 -0500 |
commit | 5e7b65e0271b6f244aa30807ed5ad3aa405a2fd5 (patch) | |
tree | 64fb533a957303acf09bd69a621265f72d568201 | |
parent | 023eae6eda47df078615b46266b01dad056a91ac (diff) |
more
-rw-r--r-- | rrdformat/format.go | 5 | ||||
-rw-r--r-- | rrdformat/marshal_xml.go | 116 |
2 files changed, 68 insertions, 53 deletions
diff --git a/rrdformat/format.go b/rrdformat/format.go index 2dbcb30..bb7459b 100644 --- a/rrdformat/format.go +++ b/rrdformat/format.go @@ -106,6 +106,11 @@ type PDPPrep struct { Scratch [10]rrdbinary.Unival } +const ( + PDPScratch_UnknownSecCnt = iota + PDPScratch_Value +) + type CDPPrep struct { Scratch [10]rrdbinary.Unival } diff --git a/rrdformat/marshal_xml.go b/rrdformat/marshal_xml.go index 8e98d10..7e39510 100644 --- a/rrdformat/marshal_xml.go +++ b/rrdformat/marshal_xml.go @@ -51,13 +51,74 @@ func (rrd RRD) MarshalXML(e *xml.Encoder, start xml.StartElement) error { return err } // 3. Data Sources - for _, ds := range rrd.DSDefs { - if err := ds.marshalXML(rrd, e, xmlStart("ds")); err != nil { + for i := range rrd.DSDefs { + // 0. Start + dsEl := xmlStart("ds") + if err := e.EncodeToken(dsEl); err != nil { + return err + } + // 1. ds_def main + if err := e.EncodeElement(" "+rrd.DSDefs[i].DSName+" ", xmlStart("name")); err != nil { + return err + } + if err := e.EncodeElement(" "+rrd.DSDefs[i].DSType+" ", xmlStart("type")); err != nil { + return err + } + // 2. ds_def parameters + switch rrd.DSDefs[i].DSType { + case DST_CDEF: + var rpnps []rrdbinary.RPNToken + for _, param := range rrd.DSDefs[i].Parameters { + rpnps = append(rpnps, param.AsRPNTokens()...) + } + str, err := rrd.RPNCompactToString(rpnps) + if err != nil { + return err + } + if err := e.EncodeElement(str, xmlStart("cdef")); err != nil { + return err + } + default: + if err := e.EncodeElement(rrd.DSDefs[i].Parameters[DSParam_MRHBCnt].AsULong(), xmlStart("minimal_heartbeat")); err != nil { + return err + } + if err := e.EncodeElement(rrd.DSDefs[i].Parameters[DSParam_MinVal].AsDouble(), xmlStart("min")); err != nil { + return err + } + if err := e.EncodeElement(rrd.DSDefs[i].Parameters[DSParam_MaxVal].AsDouble(), xmlStart("max")); err != nil { + return err + } + } + // 3. Separator + if err := e.EncodeToken(xml.CharData("\n\n")); err != nil { + return err + } + if err := e.EncodeToken(xml.Comment(" PDP Status ")); err != nil { + return err + } + // 4. pdp_prep main + if err := e.EncodeElement(rrd.PDPPreps[i].LastDS, xmlStart("last_ds")); err != nil { + return err + } + if err := e.EncodeElement(rrd.PDPPreps[i].Scratch[PDPScratch_Value].AsDouble(), xmlStart("value")); err != nil { + return err + } + if err := e.EncodeElement(rrd.PDPPreps[i].Scratch[PDPScratch_UnknownSecCnt].AsULong(), xmlStart("unknown_sec")); err != nil { + return err + } + // 5. End + if err := e.EncodeToken(dsEl.End()); err != nil { return err } } // 4. Round Robin Archives + if err := e.EncodeToken(xml.CharData("\n\n")); err != nil { + return err + } + if err := e.EncodeToken(xml.Comment(" Round Robin Archives ")); err != nil { + return err + } for _, rra := range rrd.RRADefs { if err := e.EncodeElement(rra, xmlStart("rra")); err != nil { return err @@ -88,54 +149,3 @@ func (t TimeWithUsec) MarshalXML(e *xml.Encoder, start xml.StartElement) error { } return nil } - -func (ds DSDef) marshalXML(rrd RRD, e *xml.Encoder, start xml.StartElement) error { - if err := e.EncodeToken(start); err != nil { - return err - } - // 1. DS Common - if err := e.EncodeElement(" "+ds.DSName+" ", xmlStart("name")); err != nil { - return err - } - if err := e.EncodeElement(" "+ds.DSType+" ", xmlStart("type")); err != nil { - return err - } - // 2. Parameters - switch ds.DSType { - case DST_CDEF: - var rpnps []rrdbinary.RPNToken - for _, param := range ds.Parameters { - rpnps = append(rpnps, param.AsRPNTokens()...) - } - str, err := rrd.RPNCompactToString(rpnps) - if err != nil { - return err - } - if err := e.EncodeElement(str, xmlStart("cdef")); err != nil { - return err - } - default: - if err := e.EncodeElement(ds.Parameters[DSParam_MRHBCnt].AsULong(), xmlStart("minimal_heartbeat")); err != nil { - return err - } - if err := e.EncodeElement(ds.Parameters[DSParam_MinVal].AsDouble(), xmlStart("min")); err != nil { - return err - } - if err := e.EncodeElement(ds.Parameters[DSParam_MaxVal].AsDouble(), xmlStart("max")); err != nil { - return err - } - } - // 3. Comment - if err := e.EncodeToken(xml.CharData("\n\n")); err != nil { - return err - } - if err := e.EncodeToken(xml.Comment(" PDP Status ")); err != nil { - return err - } - // 4. TODO - // End - if err := e.EncodeToken(start.End()); err != nil { - return err - } - return nil -} |