Skip to content

Commit 58258bb

Browse files
greguzgreguz
authored andcommitted
new version 0.5
rewrote all code added grunt added jshint added mocha updated README
1 parent bd267f7 commit 58258bb

9 files changed

Lines changed: 331 additions & 273 deletions

File tree

Gruntfile.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = function(grunt) {
2+
grunt.initConfig({
3+
4+
pkg: grunt.file.readJSON('package.json'),
5+
6+
jshint: {
7+
all: [
8+
'Gruntfile.js',
9+
'lib/**/*.js',
10+
'test/**/*.js'
11+
]
12+
},
13+
14+
mochaTest: {
15+
all: [
16+
'test/**/*.js'
17+
]
18+
}
19+
20+
});
21+
22+
grunt.loadNpmTasks('grunt-contrib-jshint');
23+
grunt.loadNpmTasks('grunt-mocha-test');
24+
25+
grunt.registerTask('default', [
26+
'jshint', 'mochaTest'
27+
]);
28+
grunt.registerTask('test', [
29+
'mochaTest'
30+
]);
31+
};

README.md

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,58 @@
88
npm install --save raidar
99
```
1010

11-
## Get device list
11+
## Example
12+
13+
### Code
1214

1315
``` js
1416
var raidar = require('raidar');
1517

16-
// send request, wait 10000 ms, and return founded devices
17-
raidar.request(10000, function(err, devices) {
18-
if (err)
19-
console.log('ERROR', err);
20-
else
21-
console.log('Founded devices: ' + devices.length);
18+
console.log('Waiting...');
19+
20+
raidar.request('192.168.1.160', function(err, device) {
21+
if (device) {
22+
console.log('info', device.info());
23+
console.log('volume', device.status('volume'));
24+
console.log('disk 0', device.status('disk', 0));
25+
} else {
26+
console.log(err || 'No device found');
27+
}
28+
29+
process.exit();
2230
});
2331
```
2432

33+
### Output
34+
35+
```
36+
Waiting...
37+
38+
info version=4.1.14,time=1412273301
39+
40+
volume {
41+
name: 'volume',
42+
_status: '1',
43+
status: 'warn',
44+
descr: 'Volume C: RAID Level 1, Not redundant. A disk failure will render this volume dead.; 750 GB (81%) of 921 GB used'
45+
}
46+
47+
disk 0 {
48+
name: 'disk',
49+
_status: '1',
50+
status: 'dead',
51+
descr: 'Channel 1: Seagate ST31000528AS 931 GB, 0C/32F[Dead]'
52+
}
53+
```
54+
2555
## Event definition
2656

2757
``` js
2858
var raidar = require('raidar');
2959

3060
// set event for particular device
3161
raidar.on('192.168.1.160', function(device) {
32-
console.log('Response from:', device.ip, device.mac, device.hostname);
62+
console.log('Response from:', device.mac(), device.hostname());
3363
});
3464

3565
raidar.request();
@@ -41,26 +71,17 @@ raidar.request();
4171
var raidar = require('raidar');
4272
```
4373

44-
### raidar.open(opt:Object, cb:Function)
45-
46-
Open or reset the UDP socket with given `opt` options and fire `cb` callback when socket is open. All arguments are optional.
74+
### raidar.open(cb:Function)
4775

48-
Default options:
49-
- `socketType` : socket type to use ('udp4' or 'udp6'), default `udp4`
50-
- `portToListen` : port to listen, default `57877`
51-
- `targetHost` : target host to send "request info" packet, default `255.255.255.255`
52-
- `targetPort` : target port to send "request info" packet, default `22081`
76+
Open or reset the UDP socket and fire `cb` callback when socket is open. All arguments are optional.
5377

5478
### raidar.close()
5579

5680
Close UDP socket.
5781

58-
### raidar.request(timeout:Number, callback:Function)
82+
### raidar.request(host:String, timeout:Number, callback:Function)
5983

60-
Send "request info" broadcast packet.
61-
If at least `callback` function is passed, it will execute after `timeout` ms, default 5000 ms.
62-
The event fires with `callback(err, devices)`.
63-
`err` is set in case of errors and `devices` is an array of all devices found.
84+
Send "request status" packet.
6485

6586
### raidar.on(event:String, callback:Function)
6687

@@ -110,18 +131,24 @@ Return Device Hostname.
110131

111132
Return device MAC address.
112133

113-
## Dumping all ReadyNAS messages
134+
### device.info()
114135

115-
```
116-
node node_modules/raidar/dumper optional/target/folder
117-
```
136+
Return machine info. (may vary by ReadyNAS device)
137+
138+
### device.status(part:String, index:Number)
139+
140+
Return the status of a specific part.
141+
The `part` list vary by ReadyNAS device used,
142+
the most common parts are `fan`, `ups`, `volume`, `disk` and `model`.
118143

119-
Default target folder is under node_modules `raidar` folder.
144+
`index` is used when a part is an Array,
145+
for example `device.status('disk', 1)` return the second hdd (if present),
146+
otherwise `device.status('disk')` return a Collection (if exists more than one disk).
120147

121148
## Running test
122149

123150
```
124-
node node_modules/raidar/dumper
151+
npm test
125152
```
126153

127154
## License

dumper.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)