This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
/
graphite.js
110 lines (86 loc) · 2.35 KB
/
graphite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var self = module.exports = {
publish: function(handler, event, context, callback) {
var webhook = require("./webhook_request.js");
var config = require("./config.js");
var request = self.request(config.graphite);
var data = self[handler](event, context)
webhook.publish(JSON.stringify(data), request, context, callback);
},
request: function(config) {
var https = require("https");
var req = {
proto: https,
port: config.api_port,
host: config.api_host,
path: config.api_path,
method: "post",
headers: {
"X-Graphite-Token": config.token,
}
}
return req;
},
// handles notifications from the Jenkins Notification Plugin
jenkinsNotification: function(event) {
var result = {
what: "jenkins_job"
};
if (event.build.phase == "STARTED") {
result.tags = [event.name, event.build.phase].join(",")
} else {
result.tags = [event.name, event.build.phase, event.build.status].join(",")
}
return result;
},
// handles a event created from a puppet report handler like:
//
// data = self.raw_summary
// data["host"] = self.host
// data["status"] = self.status
// data["log_count"] = self.logs.size
puppetReport: function(event) {
var tags = [event.host, event.status];
if (event.events.failure > 0) {
tags.push("failed_resources")
}
var result = {
what: "puppet_report",
tags: tags.join(",")
};
return result;
},
// {"hostname": "example.net"}
rebootPushNotification: function(event) {
var result = {
what: "reboot",
tags: event.hostname
};
return result;
},
gitHubPushNotification: function(event) {
var result = {
what: "github_push",
tags: [event.repository.full_name, event.pusher.name].join(",")
};
return result;
},
gogsPushNotification: function(event) {
var tags = [];
tags.push(event.repository.owner.username + "/" + event.repository.name);
tags.push(event.pusher.username)
var result = {
what: "gogs_push",
tags: tags.join(",")
};
return result;
},
quayPushNotification: function(event) {
var tags = [event.repository];
tags.concat(Object.keys(event.updated_tags));
var result = {
what: "quay_push",
tags: tags.join(",")
};
return result;
}
}