github.com/orofarne/hammy@v0.0.0-20130409105742-374fadfd6ecb/src/hammy/request.go (about)

     1  package hammy
     2  
     3  type IncomingValueData struct {
     4  	Timestamp uint64
     5  	Value interface{}
     6  }
     7  
     8  type IncomingHostData map[string][]IncomingValueData
     9  
    10  // Type for incoming monitoring data
    11  // Format (in json notation):
    12  //  {
    13  //    "host1": {
    14  //      "key1.1": [{
    15  //        "Timestamp": 1361785778,
    16  //        "Value": 3.14
    17  //      }]
    18  //    },
    19  //    "host2": {
    20  //      "key2.1": [{
    21  //        "Timestamp": 1361785817,
    22  //        "Value": "test string"
    23  //      }],
    24  //      "key2.2": [{
    25  //        "Timestamp": 1361785858,
    26  //        "Value": 12345
    27  //      },
    28  //      {
    29  //        "Timestamp": 1361785927,
    30  //        "Value": 999.3
    31  //      }]
    32  //    }
    33  //  }
    34  type IncomingData map[string]IncomingHostData
    35  
    36  // Type for incoming monitoring data request
    37  type IncomingMessage struct {
    38  	// Incoming monitoring data
    39  	Data IncomingData
    40  	// Processing level (0 for new data)
    41  	// Increments after each resend
    42  	Level uint32
    43  }
    44  
    45  // Response
    46  type ResponseMessage struct {
    47  	Errors map[string]string
    48  }
    49  
    50  // Interface for incoming data handler
    51  type RequestHandler interface {
    52  	Handle(data IncomingData) map[string]error
    53  }
    54  
    55  // Type for state of an host
    56  // maps keys to values with timestamps of last update
    57  // Format (in json notation):
    58  //  {
    59  //    "key1": {
    60  //      "Value": 10.3,
    61  //      "LastUpdate": 1361785927
    62  //    },
    63  //    "key2": {
    64  //      "Value": "booo!",
    65  //      "LastUpdate": 1361785778
    66  //    }
    67  type State map[string]StateElem
    68  
    69  // Type for State element
    70  type StateElem struct {
    71  	LastUpdate uint64
    72  	Value interface{}
    73  }
    74  
    75  func NewState() *State {
    76  	s := make(State)
    77  	return &s
    78  }