Browse Source

Initial commit

master
Rune Olsen 3 years ago
commit
0daa506a3e
  1. 58
      .gitignore
  2. 0
      .npmignore
  3. 21
      LICENSE
  4. 71
      MMM-ping.js
  5. 50
      README.md
  6. 25
      node_helper.js
  7. 32
      package.json

58
.gitignore

@ -0,0 +1,58 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
.DS_Store
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env

0
.npmignore

21
LICENSE

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 fewieden
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

71
MMM-ping.js

@ -0,0 +1,71 @@
/* global Module Log */
/* Magic Mirror
* Module: MMM-ping
*
* By fewieden https://github.com/fewieden/MMM-ping
*
* MIT Licensed.
*/
Module.register('MMM-ping', {
defaults: {
colored: false,
display: 'both',
hosts: [],
updateInterval: 5,
font: 'medium'
},
start() {
Log.info(`Starting module: ${this.name}`);
this.status = {};
this.checkHosts();
setInterval(() => {
this.checkHosts();
}, this.config.updateInterval * 60000);
},
checkHosts() {
this.sendSocketNotification('CHECK_HOSTS', this.config.hosts);
},
getDom() {
const wrapper = document.createElement('div');
wrapper.classList.add(this.config.font);
wrapper.style.textAlign = 'left';
const hosts = this.config.hosts;
let domainLength = this.config.hosts.length;
for (let i = 0; i < domainLength; i++) {
const isOnline = hosts[i].status;
console.log(hosts[i].name+' is '+isOnline);
if ((isOnline && (this.config.display === 'both' || this.config.display === 'online')) ||
(!isOnline && (this.config.display === 'both' || this.config.display === 'offline'))) {
const div = document.createElement('div');
const span = document.createElement('span');
span.innerHTML = isOnline ? '<span style=\"color:green;\">ONLINE : </span>' : '<span style=\"color:red;\">OFFLINE : </span>';
if (this.config.colored) {
span.innerHTML.style.color = isOnline ? 'green' : 'red';
}
const host = document.createElement('span');
host.innerHTML = hosts[i].name;
div.appendChild(span);
div.appendChild(host);
wrapper.appendChild(div);
}
}
return wrapper;
},
socketNotificationReceived(notification, payload) {
if (notification === 'HOST') {
for (var i in this.config.hosts) {
if (this.config.hosts[i].uri == payload.host.uri) {
this.config.hosts[i].status = payload.host.status;
break;
}
}
this.updateDom();
}
}
});

50
README.md

@ -0,0 +1,50 @@
# MMM-ping [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-ping/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-ping.svg?branch=master)](https://travis-ci.org/fewieden/MMM-ping) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-ping/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-ping) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-ping/badge.svg)](https://snyk.io/test/github/fewieden/mmm-ping)
Ping Module for MagicMirror<sup>2</sup>
## Example
![](.github/example.jpg)
## Dependencies
* An installation of [MagicMirror<sup>2</sup>](https://github.com/MichMich/MagicMirror)
* npm
* [ping](https://www.npmjs.com/package/ping)
## Installation
1. Clone this repo into `~/MagicMirror/modules` directory.
1. Configure your `~/MagicMirror/config/config.js`:
```
{
module: 'MMM-ping',
position: 'bottom_right',
config: {
hosts: [
{
uri: 'github.com',
name: 'GitGub'
},
{
uri: '192.168.1.200',
name: 'The server'
}
]
}
}
```
1. Run command `npm install --productive` in `~/MagicMirror/modules/MMM-ping` directory.
1. Run command `sudo chmod u+s /bin/ping`.
## Config Options
| **Option** | **Default** | **Description** |
| --- | --- | --- |
| `colored` | false | show badge in color or not |
| `display` | 'both' | what should be displayed 'online', 'offline' or 'both' |
| `hosts` | [] | addresses to ping |
| `updateInterval` | 5 | how often the module should ping the hosts in minutes |
| `font` | 'medium' | font size 'xsmall', 'small', 'medium', 'large' or 'xlarge' |

25
node_helper.js

@ -0,0 +1,25 @@
/* Magic Mirror
* Module: MMM-ping
*
* By fewieden https://github.com/fewieden/MMM-ping
*
* MIT Licensed.
*/
/* eslint-env node */
const NodeHelper = require('node_helper');
const ping = require('ping');
module.exports = NodeHelper.create({
socketNotificationReceived(notification, payload) {
if (notification === 'CHECK_HOSTS') {
payload.forEach((host) => {
ping.sys.probe(host.uri, (isAlive) => {
host.status = isAlive;
this.sendSocketNotification('HOST', { host, status: isAlive });
});
});
}
}
});

32
package.json

@ -0,0 +1,32 @@
{
"name": "mmm-ping",
"version": "1.0.0",
"description": "Ping Module for MagicMirror2",
"scripts": {
"lint": "./node_modules/.bin/eslint ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/fewieden/MMM-ping.git"
},
"keywords": [
"MagicMirror",
"ping",
"online",
"offline"
],
"author": "fewieden",
"license": "MIT",
"bugs": {
"url": "https://github.com/fewieden/MMM-ping/issues"
},
"homepage": "https://github.com/fewieden/MMM-ping#readme",
"devDependencies": {
"eslint": "^3.14.1",
"eslint-config-airbnb-base": "^11.0.1",
"eslint-plugin-import": "^2.2.0"
},
"dependencies": {
"ping": "^0.1.10"
}
}
Loading…
Cancel
Save