Skip to content
Snippets Groups Projects
Commit 32577bee authored by jurgenhaas's avatar jurgenhaas
Browse files

Implement poller for GitHub

parent ecbf01f7
No related branches found
No related tags found
No related merge requests found
Copyright (c) 2012 Francois Zaninotto Copyright (c) 2016 Jürgen Haas
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
......
...@@ -12,7 +12,7 @@ monitor: ...@@ -12,7 +12,7 @@ monitor:
apiUrl: 'http://localhost:8082/api' # must be accessible without a proxy apiUrl: 'http://localhost:8082/api' # must be accessible without a proxy
pollingInterval: 10000 # ten seconds pollingInterval: 10000 # ten seconds
timeout: 5000 # five seconds timeout: 5000 # five seconds
userAgent: NodeUptime/3.0 (https://github.com/fzaninotto/uptime) userAgent: NodeUptime/3.0 (https://gitlab.paragon-es.de/tools/uptime)
ssl: ssl:
enabled: false enabled: false
......
{ {
"name": "node-uptime", "name": "node-uptime",
"description": "Remote monitoring for HTTP applications", "description": "Remote monitoring for HTTP applications",
"version": "3.2.0", "version": "3.2.0",
"author": "Francois Zaninotto", "author": "Jürgen Haas",
"dependencies": { "dependencies": {
"mongoose": "3.6.7", "mongoose": "3.6.7",
"mongoose-lifecycle": "1.0.0", "mongoose-lifecycle": "1.0.0",
"express": "3.2.0", "express": "3.2.0",
"express-partials": "0.1.1", "express-partials": "0.1.1",
"connect-flash": "0.1.0", "connect-flash": "0.1.0",
"ejs": "0.8.3", "ejs": "0.8.3",
"config": "0.4.32", "config": "0.4.32",
"async": "0.1.22", "async": "0.1.22",
"socket.io": "0.9.14", "socket.io": "0.9.14",
"semver": "1.1.0", "semver": "1.1.0",
"moment": "2.1.0", "moment": "2.1.0",
"nodemailer": "0.3.35", "nodemailer": "0.3.35",
"net-ping": "1.1.7", "net-ping": "1.1.7",
"js-yaml": "2.1.0", "js-yaml": "2.1.0",
"webpagetest": "0.2.0", "webpagetest": "0.2.0",
"pushover-notifications": "0.1.5", "pushover-notifications": "0.1.5",
...@@ -24,14 +24,20 @@ ...@@ -24,14 +24,20 @@
"jira-connector": "^1.9.0", "jira-connector": "^1.9.0",
"request": "^2.65.0", "request": "^2.65.0",
"feedparser": "^1.1.4", "feedparser": "^1.1.4",
"node-mattermost": "^0.0.1" "node-mattermost": "^0.0.1",
"github": "^5.3.3"
}, },
"devDependencies": { "devDependencies": {
"mocha": "1.7.x", "mocha": "1.7.x",
"should": "1.1.0" "should": "1.1.0"
}, },
"keywords": ["uptime", "monitoring", "api", "check"], "keywords": [
"repository": "https://github.com/fzaninotto/uptime", "uptime",
"monitoring",
"api",
"check"
],
"repository": "https://gitlab.paragon-es.de/tools/uptime",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": "0.10.x", "node": "0.10.x",
......
/**
* Module dependencies.
*/
var GitHubApi= require('github');
var util = require('util');
var BaseTrackerSource = require('../baseSource');
var github;
/**
* GitHub TrackerSource, to receive latest notifications and report to targets
*
* @param {String} id
* @param {Integer} lastActivity
* @param {String} url
* @param {Array} params
* @api public
*/
function GitHubTrackerSource(id, lastActivity, url, params) {
GitHubTrackerSource.super_.call(this, id, lastActivity, url, params);
}
util.inherits(GitHubTrackerSource, BaseTrackerSource);
GitHubTrackerSource.type = 'GitHub';
GitHubTrackerSource.prototype.poll = function() {
var source = this;
github = new GitHubApi( {
host: source.url.substr(source.url.search('://') + 3)
});
github.authenticate({
type: "token",
token: source.password
});
github.activity.getNotifications({}, function(err, res) {
if (error) {
source.debug(error);
return;
}
if (res === undefined) {
return;
}
source.readItems(res, false);
});
};
GitHubTrackerSource.prototype.notifyItem = function(item) {
github.activity.markNotificationThreadAsRead({
id: item.id
});
return true;
};
GitHubTrackerSource.prototype.renderItem = function(item, linkCB, imageCB) {
return linkCB(item.subject.type, item.subject.url.replace('//api.', '')) + ' ' + item.subject.title;
};
GitHubTrackerSource.prototype.getItemDate = function(item) {
return item.updated_at;
};
GitHubTrackerSource.prototype.compareDate = function(a, b) {
return (Date.parse(this.getItemDate(a)) - Date.parse(this.getItemDate(b)));
};
GitHubTrackerSource.prototype.isItemNew = function(item) {
return true;
};
GitHubTrackerSource.prototype.formatDate = function(timestamp) {
return timestamp;
};
module.exports = GitHubTrackerSource;
...@@ -4,6 +4,7 @@ var TrackerSourceCollection = function(sources) { ...@@ -4,6 +4,7 @@ var TrackerSourceCollection = function(sources) {
}; };
TrackerSourceCollection.prototype.addDefaultSources = function() { TrackerSourceCollection.prototype.addDefaultSources = function() {
this.add(require('./github/githubSource.js'));
this.add(require('./jira/jiraSource.js')); this.add(require('./jira/jiraSource.js'));
this.add(require('./redmine/redmineSource.js')); this.add(require('./redmine/redmineSource.js'));
this.add(require('./rss/rssSource.js')); this.add(require('./rss/rssSource.js'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment