# Approach to send metrics to Elasticsearch in a new module

**URL:** <https://discuss.elastic.co/t/approach-to-send-metrics-to-elasticsearch-in-a-new-module/97279>\
**Category:** Beats\
**Tags:** beats-development\
**Created:** [August 16, 2017, 2:32pm UTC](https://discuss.elastic.co/t/approach-to-send-metrics-to-elasticsearch-in-a-new-module/97279 "2017-08-16T14:32:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![madou23](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@madou23](https://discuss.elastic.co/u/madou23)\
**Post date:** [August 16, 2017, 2:32pm UTC](https://discuss.elastic.co/t/approach-to-send-metrics-to-elasticsearch-in-a-new-module/97279/1 "2017-08-16T14:32:18Z")

</div>

Hi all,

I'm trying to create a new metricbeat module for Jenkins. Actually, I'm working with this wonderful API : [Jenkins API Client for Go](https://github.com/bndr/gojenkins)  
I'm trying to send all jobs information include it's builds but I'm facing a problem to implement it in module "fetch" method  
Below how build response returned from this API

```
type BuildResponse struct {
	Actions []generalObj
	Artifacts []struct {
		DisplayPath string `json:"displayPath"`
		FileName string `json:"fileName"`
		RelativePath string `json:"relativePath"`
	} `json:"artifacts"`
	Building bool `json:"building"`
	BuiltOn string `json:"builtOn"`
	ChangeSet struct {
		Items []struct {
			AffectedPaths []string `json:"affectedPaths"`
			Author struct {
				AbsoluteUrl string `json:"absoluteUrl"`
				FullName string `json:"fullName"`
			} `json:"author"`
			Comment string `json:"comment"`
			CommitID string `json:"commitId"`
			Date string `json:"date"`
			ID string `json:"id"`
			Msg string `json:"msg"`
			Paths []struct {
				EditType string `json:"editType"`
				File string `json:"file"`
			} `json:"paths"`
			Timestamp int64 `json:"timestamp"`
		} `json:"items"`
		Kind string `json:"kind"`
		Revisions []struct {
			Module string
			Revision int
		} `json:"revision"`
	} `json:"changeSet"`
	Culprits []culprit `json:"culprits"`
	Description interface{} `json:"description"`
	Duration int64 `json:"duration"`
	EstimatedDuration int64 `json:"estimatedDuration"`
	Executor interface{} `json:"executor"`
	FullDisplayName string `json:"fullDisplayName"`
	ID string `json:"id"`
	KeepLog bool `json:"keepLog"`
	Number int64 `json:"number"`
	QueueID int64 `json:"queueId"`
	Result string `json:"result"`
	Timestamp int64 `json:"timestamp"`
	URL string `json:"url"`
	MavenArtifacts interface{} `json:"mavenArtifacts"`
	MavenVersionUsed string `json:"mavenVersionUsed"`
	FingerPrint []FingerPrintResponse
	Runs []struct {
		Number int64
		URL string
	} `json:"runs"`
}

```

What's the correct approach to convert this info into a Json object sent to Elasticsearch ?  
I have already tried to extract some field as mentioned in this documentation [Creating a Metricset](https://www.elastic.co/guide/en/beats/metricbeat/current/creating-metricsets.html) and everything working well but I noticed that it only support "common.MapStr" object, how can I deal with arrays nested in the above-mentioned struct ??

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [August 17, 2017, 10:29pm UTC](https://discuss.elastic.co/t/approach-to-send-metrics-to-elasticsearch-in-a-new-module/97279/2 "2017-08-17T22:29:18Z")

</div>

> [@madou23](#):
>
> how can I deal with arrays nested in the above-mentioned struct ??

You could try leaving them as is depending on how you plan to use the fields from the objects in the arrays. The main limitation of leaving them as is is that Kibana [has trouble](https://github.com/elastic/kibana/issues/1084) rending the nested objects (but you can still query based on the fields).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 14, 2017, 10:29pm UTC](https://discuss.elastic.co/t/approach-to-send-metrics-to-elasticsearch-in-a-new-module/97279/3 "2017-09-14T22:29:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
