forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-CommonD2.yml
More file actions
46 lines (46 loc) · 1.26 KB
/
Copy pathscript-CommonD2.yml
File metadata and controls
46 lines (46 loc) · 1.26 KB
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
commonfields:
id: CommonD2
version: 1
name: CommonD2
script: |-
// Common functions script
// =======================
// This script will be appended to each d2 agent script before being executed.
// Place here all common functions you'd like to share between d2 agent scripts.
/**
* Checks if the given string represents a valid IPv4 address
* @param {String} ip - the string to check
* @returns {Boolean} true if valid IPv4 address
*/
function isIp(ip) {
var d = ip.split('.'), i = d.length;
if (i !== 4) {
return false;
}
var ok = true;
while (i-- && ok) {
ok = d[i].length !== 0 && !isNaN(parseInt(d[i])) && d[i] > -1 && d[i] < 256;
}
return ok;
}
/**
* Execute a command and pack the standard output or throw the error
* @param {String} command - the command to execute on the OS
* @returns {Void}
*/
function packOutput(command){
var output = execute(command);
if (output.Success) {
pack(output.Stdout);
} else {
throw 'Errcode:' + output.Error + '\nStderr:' + output.Stderr + '\nStdout: ' + output.Stdout;
}
}
type: javascript
tags:
- infra
- agent
comment: Common code that will be merged into each D2 agent script when it runs
scripttarget: 1
dependson: {}
timeout: 0s