ServerJS

v1.0.21


Global variable

  • INPUT string

    输入参数

  • OUTPUT any

    返回数据

  • STATUS string

    自定义返回状态,默认为:okerror

Example

log.info("input:", INPUT);
OUPUT = "Hello world!"

Packages and Functions

  • time

    // sleep: Sleep specified time
    // params: <time string>
    // return: None
    time.sleep('1s');
    
  • odb

    // mql: MQL access ODB
    // params: <mql string>, <values any...>
    // return: <result format: {data:[{}, {}...], meta:{}}> 
    var ret = odb.mql("select id from /matrix/test where name = ? and age = ?", "A", 10);
    
    // mqlx: MQL access ODB by addrs and keyspace
    // params: <mql string>, <meta object>, <values any...>
    // return: <result format: {data:[{}, {}...], meta:{}}>
    // special note: 
    //     meta special options: 
    //         addrs: ODBPATH list or DC list.
    //         keyspace: Connect keyspace.
    //         dcmode: Multiple DCs mode. all | once | random
    //         ignerr: Ignore errors when executing mql.
    var ret = odb.mqlx("select id from /matrix/test where name = ? and age = ?", {meta:"true", addrs:"127.0.0.1,127.0.0.2", keyspace:"matrix"}, "A", 10);
    var ret = odb.mqlx("select id from /matrix/test where name = ? and age = ?", {meta:"true", addrs:"DC1,DC2", keyspace:"matrix", dcmode:"once", ignerr:false}, "A", 10);
    
    // mql: Search access ODB
    // params: 
    //     <search string>
    //     <meta object> optional
    // return: 
    //     <result format: {data:[{}, {}...], meta:{}}>
    var ret = odb.search("wecise | print id | top 1", {meta:"false"});
    
    // getid: Get object id by object table
    // params: <object object>
    // return: <id string>
    var id = odb.getid({column0:"mxsvr1", class:"/matrix/test"});
    
    // classlist: Get class list by class name
    // params: <class string>
    // return: <class object list>
    var ret = odb.classlist("/matrix/test");
    
    // classfields: Get fields by cid
    // params: <cid string>
    // return: <fields list>
    var ret = odb.classfields("/matrix/test");
    
    // fieldtypes: Get fields by cid
    // params: None
    // return: <field type object>
    var ret = odb.fieldtypes();
    
    // getclassid: Get cid by class name
    // params: <class string>
    // return: <cid int>
    var ret = odb.getclassid("/matrix/test");
    
    // refresh: Refresh odb
    // params: None
    // return: None
    odb.refresh();
    
  • appcontext

    // rawget: Get raw cache, key-value mode
    // params: <key string>
    // return: <value string>
    var id = appcontext.rawget("testkey");
    
    // rawset: Set raw cache, key-value mode
    // params: <key string>, <value string>, <ttl second number>
    // return: None
    appcontext.rawset("testkey", "testvalue", 120);
    
    // create: Create collection cache, collection mode
    // params: <collection name string>, <value table>, <ttl second number>
    // return: <id string>
    var id = appcontext.create("zoo", {name:"monkey", room:1}, 120);
    
    // getall: Get collection by condition
    // params: <collection name string>, <query condition string>
    // return: <result table>
    // where: Query logic expression
    //        ||
    //        &&
    //        = != > < >= <= ~= !~= is isnot
    //        + -
    //        * / %
    //        ^
    //        ( )
    var list = appcontext.getall("zoo", "room == 1");
    
    // getfirst: Get the first data of the collection
    // params: <collection name string>
    // return: <result table>
    var ret = appcontext.getfirst("zoo");
    
    // getlast: Get the last data of the collection
    // params: <collection name string>
    // return: <result table>
    var ret = appcontext.getlast("zoo");
    
    // get: Get data of the collection by id
    // params: <collection name string>, <id string>
    // return: <result table>
    var ret = appcontext.get("zoo", "e898853a-74ee-11e8-941c-9eb6d01c8f95");
    
    // update: Update data of the collection by id
    // params: <collection name string>, <id string>, <value table>, <ttl number>
    // return: None
    appcontext.update("zoo", "e898853a-74ee-11e8-941c-9eb6d01c8f95", {name:"monkey", room:2}, 120);
    
    // deleteall: Delete collection all data
    // params: <collection name string>
    // return: None
    appcontext.deleteall("zoo");
    
    // delete: Delete collection data by id
    // params: <collection name string>, <id string>
    // return: None
    appcontext.delete("zoo", "e898853a-74ee-11e8-941c-9eb6d01c8f95");
    
  • message

    // send: Send message
    // params: <source string>, <subject string>, <title string>, <msg string>
    // return: None
    message.send("test_source", "test_event", "test_title", "Test event message.")
    
  • http

    // get: Http get request
    // params: url<string>, params<object>, successfunc<function>, errfunc<function>
    // return: none
    http.get("http://127.0.0.1:8080/test", {page:"1"}, function(message){
        // success func
        log.info(message.data);
    }, function(message){
        // error func
        log.info(message.data);
    })
    
    // post: Http post request
    // params: url<string>, form<object>, successfunc<function>, errfunc<function>
    //     form: {name1:['',''...],name2:['',''...]}
    // return: none
    http.post("http://127.0.0.1:8080/test", {fruit:["apple"], from:["Beijing","Hebei"]}, function(message){
        // success func
        log.info(message.data);
    }, function(message){
        // error func
        log.info(message.data);
    })
    
    // postjson: Http post json request
    // params: url<string>, json<object>, successfunc<function>, errfunc<function>
    // return: none
    http.postjson("http://127.0.0.1:8080/test", {fruit:"apple", from:["Beijing","Hebei"]}, function(message){
        // success func
        log.info(message.data);
    }, function(message){
        // error func
        log.info(message.data);
    })
    
    // put: Http put request
    // params: url<string>, form<object>, successfunc<function>, errfunc<function>
    //     form: {name1:['',''...],name2:['',''...]}
    // return: none
    http.put("http://127.0.0.1:8080/test", {fruit:["apple"], from:["Beijing","Hebei"]}, function(message){
        // success func
        log.info(message.data);
    }, function(message){
        // error func
        log.info(message.data);
    })
    
    // putjson: Http put json request
    // params: url<string>, json<object>, successfunc<function>, errfunc<function>
    // return: none
    http.putjson("http://127.0.0.1:8080/test", {fruit:"apple", from:["Beijing","Hebei"]}, function(message){
        // success func
        log.info(message.data);
    }, function(message){
        // error func
        log.info(message.data);
    })
    
    // delete: Http delete request
    // params: url<string>, params<object>, successfunc<function>, errfunc<function>
    // return: none
    http.delete("http://127.0.0.1:8080/test", {page:"1"}, function(message){
        // success func
        log.info(message.data);
    }, function(message){
        // error func
        log.info(message.data);
    })
    
    // do: Http request
    // params: method<string>, url<string>, header<object>, body<string>, successfunc<function>, errfunc<function>, timeout<int>
    // return: none
    /* special note:
       Digest authorization:
           header: {'Authorization': 'Digest username="user",password="pass"'}
    */
    http.do("POST", "http://127.0.0.1:8080/test", {"Data-Type":"json"}, '{"fruit":"apple"}', function(message){
        // success func
        log.info(message.data);
    }, function(message){
        // error func
        log.info(message.data);
    }, 10)
    
  • concurrent

    // run: Concurrent execution function
    // params: funcName<string>, funcParams<different array>
    // return: <result array>
    var ret = concurrent.run("odb.mql", [["select id from /matrix/test"], ["select id from /matrix/test2"]]);
    
  • tagdir

    // update: Tagdir update function
    // params: domain<string>, creator<string>, tagPath<string>
    // return: none
    var ret = tagdir.update("test", "system", "fruit/apple/red");
    
    // delete: Tagdir delete function
    // params: domain<string>, creator<string>, tagPath<string>
    // return: none
    var ret = tagdir.delete("test", "system", "fruit/apple/red");
    
    // move: Tagdir move function
    // params: domain<string>, creator<string>, tagPath<string>, toPath<string>
    // return: none
    // exp:
    // fruit           ->     fruit
    //   - apple       ->       - apple
    //       - red     ->       - pear
    //   - pear        ->         - red
    var ret = tagdir.move("test", "system", "fruit/apple/red", "fruit/pear");
    
    // get: Tagdir get tree function
    // params: domain<string>, creator<string>
    // return: <result tag tree>
    var ret = tagdir.get("test", "system");
    
    // getall: Tagdir get all tree function
    // params: domain<string>
    // return: <result tag tree list>
    var ret = tagdir.getall("test");
    
    // rename: Tagdir rename function
    // params: domain<string>, creator<string>, tagPath<string>, toPath<string>
    // return: none
    // exp:
    // fruit           ->     fruit
    //   - apple       ->       - apple
    //       - red     ->           - green
    var ret = tagdir.rename("test", "system", "fruit/apple/red", "fruit/apple/green");
    
    // nodata: Tagdir check no data function
    // params: tagPath<string>
    // return: <bool>
    var ret = tagdir.nodata("fruit/apple"); // if no data return true
    
    // addtags: Add tags to data
    // params: domain<string>, creator<string>, ids<string array>, tags<string array>
    // return: none
    var ret = tagdir.addtags("test", "system", ["id1", "id2"], ["tag1", "tag2"]);
    
    // deletetags: Delete tags to data
    // params: ids<string array>, tags<string array>
    // return: none
    var ret = tagdir.deletetags(["id1", "id2"], ["tag1", "tag2"]);
    
  • dfs

    // write: DFS write file function (only support text file)
    // params: filePath<string>, content<string>
    // return: none
    dfs.write("/temp/a.txt", "Hello world!");
    
    // exists: Check if the dfs file exists
    // params: filePath<string>
    // return: <bool>
    var ok = dfs.exists("/temp/a.txt");
    
    // read: DFS read file function (only support text file)
    // params: filePath<string>
    // return: <string>
    var content = dfs.read("/temp/a.txt");
    
    // readdir: DFS read dir function (only support text file)
    // params: filePath<string>
    // return: <files list>
    var files = dfs.readdir("/temp");
    
    // remove: Remove file or directory
    // params: filePath<string>
    // return: none
    dfs.remove("/temp/a.txt");
    
    // copy: DFS copy path to path
    // params: srcPath<string>, dstPath<string>
    // return: none
    dfs.copy("/temp/a.txt", "/temp2");
    
    // move: DFS move path to path
    // params: srcPath<string>, dstPath<string>
    // return: none
    dfs.move("/temp/a.txt", "/temp2");
    
    // settags: DFS set tags
    // params: fullnames<[]string>, tags<[]string>
    // return: none
    dfs.settags(["/temp/a.txt", "/temp/b.txt"], ["tag1", "tag2"]);
    
    // deltags: DFS del tags
    // params: fullnames<[]string>, tags<[]string>
    // return: none
    dfs.deltags(["/temp/a.txt", "/temp/b.txt"], ["tag1", "tag2"]);
    
  • graphalg

    // endpoints: Find endpoints function
    // params: cypher<string>
    // return: <string>
    var ret = graphalg.endpoints("match ('biz:b1')-[:contain]->()-[:contain]->()");
    
    // connectedGraphs: Find connected graphs function
    // params: objects<[]string>, level <int>
    // return: <[][]string>
    var ret = graphalg.connectedGraphs(["cassandra:c1", "biz:b1", "linux:h1"], 1);
    
  • aialg

    // cafp: CA and FP algorithm function
    // params: data<object array>, idFieldName<string>, valueFieldName<string>, minPts<int number>, esp<float number>, times<int number>
    // return: <array[array[string], int]>
    var data = [
        {id:"啤酒", value:100}, {id:"鸡蛋", value:20}, {id:"牛奶", value:45},
        {id:"尿布", value:100}, {id:"酱油", value:20}, {id:"面包", value:100},
        {id:"花生", value:100}, {id:"大米", value:100}, {id:"香肠", value:45},
        {id:"啤酒", value:20}, {id:"尿布", value:20}, {id:"香肠", value:45},
        {id:"啤酒", value:45}, {id:"尿布", value:45}, {id:"香肠", value:45}
    ];
    var ret = aialg.cafp(data, "id", "value", 1, 10, 2);
    // result: [[["尿布"],3],[["啤酒"],3],[["啤酒","尿布"],3]]
    
  • forward

    // send: Forward data to rule by nats or streaming, default streaming mode (isOldRule is false)
    // params: rule<string>, data<string>, isOldRule<bool>
    // return: none
    forward.send("/matrix/rules/event", "host1\tbiz1\torg1\tapp1\tinst1\tparam1\t1\t5\ttest\ttest\t1569224900555", false);
    
  • webcontext

    // user: Get login user info
    // params: none
    // return: <user object>
    var user = webcontext.user();
    
    // user: Write operation log
    // params: module<string>, operation<string>, status<int 0 or 1>
    // return: none
    webcontext.writeOperLog('TestApp', 'View list', 0);
    
    // addUser: Add user
    // params: user<object>
    /* User object:
    {
        "parent":    "string",      // required
        "username":  "string",      // required
        "passwd":    "string",      // required
        "auth":      "string",
        "otype":     "usr | org",   // required
        "grpset":    ["string"...],
        "lastname":  "string",
        "firstname": "string",
        "gender":    "string",
        "address":   "string",
        "email":     ["string"...],
        "wechat":    "string",
        "mobile":     ["string"...],
        "telephone": ["string"...],
        "remark":     "string",
        "status":     int,
        "isadmin":   true | false,  // required
        "isactive":  true | false,  // required
        "config":    {"string":"string"}
    }
    */
    // return: uid<string>
    var user = {username:'testuser', passwd:'testuser', parent:'/用户组', otype:'usr', isadmin:false, isactive: true};
    var uid = webcontext.addUser(user);
    
    // addUser: Edit user
    // params: uid<string>, editUser<object>
    /*
    {
        "auth":      "string",
        "grpset":    ["string"...],
        "lastname":  "string",
        "firstname": "string",
        "gender":    "string",
        "address":   "string",
        "email":     ["string"...],
        "wechat":    "string",
        "mobile":     ["string"...],
        "telephone": ["string"...],
        "remark":     "string",
        "status":     int,
        "isadmin":   true | false,
        "isactive":  true | false,
        "config":    {"string":"string"},
        "passwd":    "string"
    }
    */
    // return: none
    var editUser = {firstname:'Hui', lastname:'Li'};
    webcontext.editUser('UID123', editUser);
    
    // deleteUser: Edit user
    // params: uid<string>
    // return: none
    webcontext.deleteUser('UID123');
    
    // moveUser: Move user to org
    // params: uid<string>, oid<string>
    // return: newUID<string>
    webcontext.moveUser('UID123', 'OID101');
    
    // admin: Enable or disable admin group
    // params: enable<bool>
    // return: none
    webcontext.admin(true);
    
  • nlp

    // update: Update nlp
    // params: path<string>
    // return: none
    nlp.update('/etc/nlp/devops.txt');
    
    // answer: NLP answer query
    // params: domain<string>, query<string>
    // return: <result list>
    var ret = nlp.answer('devops', '查询昨天的事件');
    
  • perm

    // ui: Get html ui perms
    // params: filename<string>
    // return: <perm list>
    var ret = perm.ui('/app/testapp/test.html');
    
    // set: Set group perms by ids
    // params: class<string>, ids<string array>, groups<string array>
    // return: none
    var ret = perm.set('/test', ['ID1', 'ID2'], ['GRPID1', 'GRPID2']);
    
    // getGroupList: Get perms group list
    // params: parent<string>
    // return: <group list>
    var ret = perm.getGroupList('');
    
    // getGroup: Get perms group by id
    // params: id<string>
    // return: <group object>
    var ret = perm.getGroup('4370160790923826435');
    
    // setGroupTags: Set tag permission of group
    // params: domain<string>, tagexpr<string>, group<string>
    // return: none
    perm.setGroupTags('test', 'test/tag1,test/tag2+test/tag3', '/testgroup');
    
    // getGroupTags: Get tag permission of group
    // params: domain<string>, group<string>
    // return: <tagexpr object>
    var ret = perm.getGroupTags('test', '/testgroup');
    
    // setGroupApps: Set apps of group
    // params: apps<string array>, group<string>
    // return: none
    perm.setGroupApps(['testapp1', 'testapp2'], '/testgroup');
    
    // getGroupApps: Get apps of group
    // params: group<string>
    // return: <string array>
    var ret = perm.getGroupApps('/testgroup');
    
    // setGroupData: Set group data by group name
    // params: group<string>, class<string>, where<string>
    // return: none
    var ret = perm.setGroupData('/testgroup', '/testclass', "name='N1'");
    
    // delGroupData: Delete group data by group name
    // params: group<string>, class<string>
    // return: none
    var ret = perm.delGroupData('/testgroup', '/testclass')
    
    // getGroupData: Get group data by group name
    // params: group<string>
    // return: <data object >
    var ret = perm.getGroupData('/testgroup')
    
    // getAppFuncs: Get app functions
    // params: name<string>, page<string>
    // return: <funcs list>
    var ret = perm.getAppFuncs('testapp', 'index.html')
    
  • job

    // list: Get job list
    // params: none
    // return: <job list>
    var ret = job.list();
    
    // exec: Exec job
    // params: jobName<string>, param<string>, receiveOutput<bool>, timeout<int>
    // return: <result object>
    var ret = job.exec('A@test', '{"p1":"a"}', false, 10);
    
    // execBatch: Batch exec job
    // params: jobs<list>, timeout<int>
    /* Jobs list
       [
           {
               'name': 'A@test/t1', // Job fullname
               'param': '{"p1":}', // Job params
               'timeout': 10 // Job timeout.(seconds)
           }
           .
           .
           .
       ]
    */
    // return: <result object>
    var ret = job.execBatch([{name:'A@test', param:'{"p1":"a"}', timeout:5}, {name:'B@test', param:'{"p2":"b"}', timeout:5}], 10);
    
    // create: Create job
    // params: jobdef<object>
    /* Jobdef object
      {
          "name": "A", // Job name (required)
          "dir": "test/t1",  // Job dir (required)
          "description": "desc",
          "group": "group1", // 'group' or 'host' must be have one
          "groupmode": "one | parallel | sequence",
          "groupskip": false,
          "host": ["host1", "host2"],
          "begin": "print('begin')", // lua script
          "end": "print('end')", // lua script
          "exec": ["echo", "echo"], // Exec command list (required)
          "arg": ["a", "b"],
          "argenc": [false, false],
          "schedule": "cron * * * * *",
          "timeout": 10,
          "algorithm": "round", // round, weight, rate
          "limit": 0, // rate/second
          "queue": "matrix.rules.test",
          "enable": true,
          "tag": ["t1", "t2"]
      }
    */
    // return: <jobname string>
    var ret = job.create({"name":"A", "dir":"test/t1", "exec":["echo"], "arg":["a"], "argenc":[false]});
    
    // update: Update job
    // params: jobdef<object>
    /* Jobdef object
      {
          "name": "A", // Job name (required)
          "dir": "test/t1",  // Job dir (required)
          "description": "desc",
          "group": "group1", // 'group' or 'host' must be have one
          "groupmode": "one | parallel | sequence",
          "groupskip": false,
          "host": ["host1", "host2"],
          "begin": "print('begin')", // lua script
          "end": "print('end')", // lua script
          "exec": ["echo", "echo"], // Exec command list (required)
          "arg": ["a", "b"],
          "argenc": [false, false],
          "schedule": "cron * * * * *",
          "timeout": 10,
          "algorithm": "round", // round, weight, rate
          "limit": 0, // rate/second
          "queue": "matrix.rules.test",
          "enable": true,
          "tag": ["t1", "t2"]
      }
    */
    // return: <jobname string>
    var ret = job.update({"name":"A", "dir":"test/t1", "exec":["echo"], "arg":["a"], "argenc":[false]});
    
    // merge: Merge job
    // params: jobdef<object>
    /* Jobdef object
      {
          "name": "A", // Job name (required)
          "dir": "test/t1",  // Job dir (required)
          "description": "desc",
          "group": "group1", // 'group' or 'host' must be have one
          "groupmode": "one | parallel | sequence",
          "groupskip": false,
          "host": ["host1", "host2"],
          "begin": "print('begin')", // lua script
          "end": "print('end')", // lua script
          "exec": ["echo", "echo"], // Exec command list (required)
          "arg": ["a", "b"],
          "argenc": [false, false],
          "schedule": "cron * * * * *",
          "timeout": 10,
          "algorithm": "round", // round, weight, rate
          "limit": 0, // rate/second
          "queue": "matrix.rules.test",
          "enable": true,
          "tag": ["t1", "t2"]
      }
    */
    // return: <jobname string>
    var ret = job.merge({"name":"A", "dir":"test/t1", "exec":["echo"], "arg":["a"], "argenc":[false]});
    
    // exist: Check if the job exists
    // params: jobname<string>
    // return: <bool>
    var ret = job.exist('A@test/t1');
    
    // delete: Delete job
    // params: jobname<string>
    // return: none
    job.delete('A@test/t1');
    
    // get: Get job
    // params: jobname<string>
    // return: <job object>
    var ret = job.get('A@test/t1');
    
    // enable: Enable job
    // params: jobname<string>
    // return: none
    var ret = job.enable('A@test/t1');
    
    // disable: Disable job
    // params: jobname<string>
    // return: none
    var ret = job.disable('A@test/t1');
    
    // sync: Sync job to db
    // params: none
    // return: none
    job.sync();
    
    // setContext: Set job context
    // params: ctxkey<string>, name<string>, value<string>, ttl<int>
    // return: none
    var ret = job.setContext('testkey', 'testname', '{"title":"a","current":"b", "status":"c"}', 86400);
    
    // putContext: Put job context
    // params: ctxkey<string>, name<string>, value<string>, ttl<int>
    // return: none
    var ret = job.putContext('testkey', 'testname', '{"title":"a","current":"b", "status":"c"}', 86400);
    
    // getContext: Get job context
    // params: ctxkey<string>, prefix<string>
    // return: <ctx object>
    var ret = job.getContext('testkey', 'testkey/t1');
    
    // deleteContext: Get job context
    // params: ctxkey<string>, name<string>, clear<bool>, ttl<int>
    // return: none
    job.deleteContext('testkey', 'testname', true, 86400);
    
  • depot

    // list: Get depot list
    // params: none
    // return: <list array>
    var ret = depot.list();
    
    // get: Get depot by name or version
    // params: name<string>, version<string>
    // return: <depot object>
    var ret = depot.get('test1', '1.0');
    
    // getFile: Get depot file
    // params: name<string>, version<string>, filepath<string>
    // return: <content string>
    var ret = depot.getFile('test1', '1.0', 'test.sh');
    
    // updateFile: Update depot file content
    // params: obj<object>
    /*
      {
          "name": "test1", // Depot name (required)
          "version": "1.0",  // Depot version (required)
          "newversion": "1.1", // Depot new version (required)
          "remark": "test depot",
          "tags": ["tag1", "tag2"],
          "filepath": "test.sh", // Depot file path (required)
          "content": "echo b", // Depot file content (required)
          "type": "M" // M | A | D (required M:modify, A:add, D:delete)
      }
    */
    // return: none
    depot.updateFile({'name':'test1', 'version':'1.0', 'newversion':'1.1', 'remark':'test depot', 'tags':['t1', 't2'], 'filepath':'test.sh', 'content':'echo b', 'type':'M'});
    
    // diffFiles: File difference
    // params: name<string>, version<string>, compareVersion<string>
    // return: <diff object>
    var ret = depot.diffFiles('test1', '1.0', '1.1');
    
    // delete: Delete depot
    // params: name<string>
    // return: none
    depot.delete('test1');
    
    // exist: Check if depot exists
    // params: name<string>, version<string>
    // return: <bool>
    var ret = depot.exist('test1', '1.0');
    
    // deploy: Deploy depot
    // params: obj<object>
    /*
      {
          "hosts": ["host1", "host2"], // Deploy to hosts (required)
          "depots": [
              {"name": "test1", "version": "1.0"},
              {"name": "test2", "version": "1.0"}
          ],  // Depots (required)
          "command": "echo ok",
          "remotepath": "", // SSH host needs
          "timeout": 60 // Deployment timeout
      }
    */
    // return: <cmdOut string>
    var ret = depot.deploy({'hosts':['host1', 'host2'], 'depots':[{'name':'test1', 'version':'1.0'},{'name':'test2', 'version':'1.0'}], 'command':'echo ok'});
    
    // undeploy: Undeploy depot
    // params: obj<object>
    /*
      {
          "hosts": ["host1", "host2"], // Deploy to hosts (required)
          "depots": [
              {"name": "test1", "version": "1.0"},
              {"name": "test2", "version": "1.0"}
          ],  // Depots (required)
          "command": "echo ok"
      }
    */
    // return: none
    var ret = depot.undeploy({'hosts':['host1', 'host2'], 'depots':[{'name':'test1', 'version':'1.0'},{'name':'test2', 'version':'1.0'}], 'command':'echo ok'});
    
  • policy

    // addCMD: Add cmd policy
    // params: obj<object>
    /*
      {
          "name":"testsh", // Policy name (required)
          "rule":"/matrix/rules/test", // (required)
          "command":"test.sh",  // (required)
          "depotname":"testsh", // if ctype = 0, not empty
          "depotversion":"1.0", // if ctype = 0, not empty
          "depotcommand":"echo ok",
          "ctype":0,  // 0:depot, 1:command (required)
          "interval":10, // (required)
          "unit":"second", // year | month | day | hour | minute | second
          "split":true,
          "delimiter":"\n",
          "delimitereol":false,
          "isdaemon":false,
          "hosts":["wecise"], // If not empty, then auto deploy
          "tags":["test"],
          "attrs":{} // toe protocol attrs
      }
    */
    // return: none
    var ret = policy.addCMD({'name':'testsh', 'rule':'/matrix/rules/test', 'command':'test.sh', 'depotname':'test1', 'depotversion':'1.0', 'ctype':0, 'interval':10, 'unit':'second', 'split':true, 'delimiter':'\n', 'delimitereol':false, 'host':['wecise'], 'tags':['test'], 'attr':{}});
    
    // addLog: Add log policy
    // params: obj<object>
    /*
      {
            "name":"testlog", // Policy name (required)
            "rule":"/matrix/rules/log/etcd", // (required)
            "dir":"/opt/matrix/var/logs/etcd", // (required)
            "match":"out.log", // (required)
            "delimiter":"\n",
            "delimitereol":false,
            "hosts":["wecise"],
            "tags":["test"],
            "attrs":{}
      }
    */
    // return: none
    var ret = policy.addLog({'name':'testlog', 'rule':'/matrix/rules/test', 'dir':'/opt/matrix/var/logs/test', 'match':'out.log', 'delimiter':'\n', 'delimitereol':false, 'host':['wecise'], 'tags':['test'], 'attr':{}});
    
    // delete: Delete policy
    // params: name<string>
    // return: none
    policy.delete('testsh');
    
    // deploy: Deploy policy
    // params: name<string>, hosts<string array>
    // return: none
    policy.deploy('testsh', ['wecise', 'wecise2']);
    
    // undeploy: Undeploy policy
    // params: name<string>, hosts<string array>
    // return: none
    policy.undeploy('testsh', ['wecise', 'wecise2']);
    
    // start: Start policy
    // params: name<string>, hosts<string array>
    // return: none
    policy.start('testsh', ['wecise', 'wecise2']);
    
    // stop: Stop policy
    // params: name<string>, hosts<string array>
    // return: none
    policy.stop('testsh', ['wecise', 'wecise2']);
    
  • zabbix

    // deploy: Deploy zabbix policy
    // params: name<string>, version<string>, hosts<string array>, key<string>, command<string>
    // return: none
    zabbix.deploy('testsh', '1.0', ['wecise', 'wecise2'], 'testkey', 'test.sh');
    
    // undeploy: Undeploy zabbix policy
    // params: name<string>, version<string>, hosts<string array>
    // return: none
    zabbix.undeploy('testsh', '1.0', ['wecise', 'wecise2']);
    
    // start: Start zabbix agent
    // params: hosts<string array>
    // return: none
    zabbix.start(['wecise', 'wecise2']);
    
    // stop: Stop zabbix agent
    // params: hosts<string array>
    // return: none
    zabbix.stop(['wecise', 'wecise2']);
    
    // restart: Restart zabbix agent
    // params: hosts<string array>
    // return: none
    zabbix.restart(['wecise', 'wecise2']);
    
  • consolelog

    // rule: Get rule console log
    // params: name<string>, levels<int array>, maxtime<int number>, mintime<int number>, limit<int>, position<string>
    // return: res<object>
    var res = consolelog.rule('/matrix/rules/test', [], 0, 0, 20, '');
    
    // ruleDelete: Delete rule console log by name
    // params: name<string>
    // return: none
    var res = consolelog.ruleDelete('/matrix/rules/test');
    
    // ruleTruncate: Truncate rule console log
    // params: none
    // return: none
    var res = consolelog.ruleTruncate();
    
    // serverjs: Get serverjs console log
    // params: name<string>, levels<int array>, maxtime<int number>, mintime<int number>, limit<int>, position<string>
    // return: res<object>
    var res = consolelog.serverjs('/script/test.js', [3, 4, 5, 6], 1610942841812, 1610942821812, 20, '');
    
    // serverjsDelete: Delete serverjs console log by name
    // params: name<string>
    // return: none
    var res = consolelog.serverjsDelete('/script/test.js');
    
    // serverjsTruncate: Truncate serverjs console
    // params: none
    // return: none
    var res = consolelog.serverjsTruncate();
    
    // trigger: Get trigger console log
    // params: name<string>, levels<int array>, maxtime<int number>, mintime<int number>, limit<int>, position<string>
    // return: res<object>
    var res = consolelog.trigger('/matrix/test', [3, 4, 5, 6], 1610942841812, 1610942821812, 20, '');
    var resNext = consolelog.trigger('/matrix/test', [3, 4, 5, 6], 1610942841812, 1610942821812, 20, res.position);
    
    // triggerjsDelete: Delete trigger console log by name
    // params: name<string>
    // return: none
    var res = consolelog.triggerjsDelete('/matrix/test');
    
    // triggerTruncate: Truncate trigger console
    // params: none
    // return: none
    var res = consolelog.triggerTruncate();
    
  • rule

    // refreshRuleClassCache: Refresh rule class cache
    // params: class<string>
    // return: none
    rule.refreshRuleClassCache('/matrix/test');
    
    // globalCacheList: Get rule global cache list
    // params: domain<string global | omnibus>, name<string>
    // return: list<array>
    var res = rule.globalCacheList('', ''); // Get [domain:name] list
    var res = rule.globalCacheList('global', 'testdata1'); // Get [domain:name] keys
    
    // globalCacheQuery: Get rule global cache by key
    // params: domain<string 'global' | 'omnibus'>, name<string>, key<string>
    // return: value<any>
    var res = rule.globalCacheQuery('global', 'testdata1', 'total');
    
    // globalCacheRemove: Remove rule global cache by key
    // params: domain<string 'global' | 'omnibus'>, name<string>, key<string>
    // return: none
    var res = rule.globalCacheRemove('global', 'testdata1', 'total');
    
    // memoryCacheList: Get rule memory cache list
    // params: name<string>
    // return: res<array | object>
    var res = rule.memoryCacheList(''); // Get table names
    var res = rule.memoryCacheList('TESTCACHE'); // Get table info
    
    // memoryCacheQuery: Query rule memory cache
    // params: name<string>, where<string>, queryfields<string>, values<array>
    // return: res<array>
    var res = rule.memoryCacheQuery('TESTCACHE', "\"group\" = ? and key = ?", 'key, msg, group', ['G1', 'KEY74']);
    
    // memoryCacheRemove: Remove rule memory cache
    // params: name<string>
    // return: none
    rule.memoryCacheRemove('TESTCACHE');
    
    // memoryCacheQuery: Reload rule memory cache
    // params: name<string>
    // return: none
    var res = rule.memoryCacheReload('TESTCACHE');
    
  • etcd

    // put: Put node
    // params: key<string>, val<string>
    // return: none
    etcd.put('/foo/bar', 'Hi');
    
    // putTTL: Put node using ttl
    // params: key<string>, val<string>, ttl<int>
    // return: none
    etcd.putTTL('/foo/bar', 'Hi', 5);
    
    // del: Delete node
    // params: key<string>
    // return: none
    etcd.del('/foo/bar');
    
    // get: Get node value
    // params: key<string>
    // return: value<string>
    var val = etcd.get('/foo/bar');
    
    // get: Get node tree
    // params: key<string>
    // return: tree<Object>
    var tree = etcd.getNode('/foo');
    
  • nats

    // request: Request message by nats extend
    // params: subject<string>, message<string>, timeout<int>
    // return: value<string>
    var resp = nats.request('test', 'Hello consumer!', 1);
    
    // nativePublish: Natively publish messages to the nats subject
    // params: addr<string>, subject<string>, data<string>, isStream<bool>
    // return: None
    nats.nativePublish('nats://user:user@127.0.0.1:4222', 'MATRIX-RULES-TEST-TESTDATA.rule', 'Test data', true);
    
    // nativeSubscribe: Native subscription to messages from nats subject
    // params: addr<string>, subjects<string array>, queue<string>, isStream<bool>, durable<string>, consumeNum<int>, consumeTime<string>, consumeFunc<function>
    // return: None
    nats.nativeSubscribe('nats://user:user@127.0.0.1:4222', ['MATRIX-RULES-TEST-TESTDATA1.>'], 'parser', true, 'MATRIX-RULES-TEST-TESTDATA1', 1, '10s', function(data){
        log.info(data);
    });
    
    // purgeStream: Purges stream messages
    // params: addr<string>, streams<string array>
    // return: None
    // note: The name can use the * wildcard character. exp: TEST*, *TEST, *TEST*
    nats.purgeStream('nats://user:user@127.0.0.1:4222', ['STREAM-PARSER-JOB', 'STREAM-SCHED-*', '*-RULES-*']);
    
  • kafka

    // kafka: Send message to topic
    // params: topic<string>, msg<string>, addrs<string array>, version<string>
    // return: None
    kafka.send('topic', 'ok', {'127.0.0.1:9092'}, '2.1.1');
    
  • convert

    // xmlToJson: Convert xml string to json object
    // params: xmlstr<string>
    // return: jsobj<object>
    var js = convert.xmlToJson('<?xml version="1.0" encoding="UTF-8"?><profile><element active="true"><fields><server>21.33.137.33</server><timeout>0</timeout></fields></element></profile>');
    
  • base64

    // encode: Encode text string to base64 string
    // params: text<string>
    // return: code<string>
    var str = base64.encode('wecise'); // output: d2VjaXNl
    
    // decode: Decode base64 string to text string
    // params: code<string>
    // return: text<string>
    var str = base64.decode('d2VjaXNl'); // output: wecise
    
  • crypto

    // murmur3: Hash text to murmur3
    // params: text<string>
    // return: hash<string>
    var res = crypto.murmur3('Hello text!');
    
    // md5: Hash text to md5
    // params: text<string>
    // return: hash<string>
    var res = crypto.md5('Hello text!');
    
    // md5: Get the CRC-32 checksum of text
    // params: text<string>
    // return: crc32<string>
    var res = crypto.crc32('Hello text!');
    
  • regmatch

    // match: Match text against a regular configuration file. (file path on etcd: /<keyspace>/data/regmatch/testregexp)
    //        In the /<keyspace>/data/regmatch directory of etcd.
    //        Content format: <name>|<tag>|<regexp>
    // params: domain<string>, text<string>
    // return: matched<list>
    var res = regmatch.match('testregexp', 'ls /\ncat /etc/profile');
    
  • excel

    // create: Write data or images to xlsx file
    // params: dfspath<string>, table<array>
    // return: None
    // note: Table structure: 
    // [
    //     {
    //         "name": "sheet1",
    //         "images": [
    //             {"path":"/tmp/1.png", "x_offset": 20, "y_offset": 20, "x_scale": 0.5, "y_scale": 0.5, "autofit": false},
    //             {"path":"/tmp/2.png"}
    //         ],
    //         "data": [["NAME", "AGE"],["TOM", 10],["JACK", 11],["KATE", 12]],
    //         "style": {
    //             "style1":{
    //                 "font": {
    //                             "bold":true,
    //                             "italic":true,
    //                             "family":"Times New Roman",
    //                             "size":36,
    //                             "color":"#777777",
    //                             "underline":"single"
    //                         },
    //                 "alignment": {"horizontal":"center","vertical":"center"},
    //                 "fill": {"type":"pattern","color":["#FFF8DC"],"pattern":3},
    //                 "border":[
    //                     {"type":"left","color":"#DCDCDC","style":1},
    //                     {"type":"top","color":"#DCDCDC","style":1},
    //                     {"type":"bottom","color":"#DCDCDC","style":1},
    //                     {"type":"right","color":"#DCDCDC","style":1},
    //                     {"type":"diagonalDown","color":"A020F0","style":9},
    //                     {"type":"diagonalUp","color":"A020F0","style":8}
    //                 ],
    //                 "protection":{"hidden":true, "locked":true},
    //                 "number_format": 188,
    //                 "decimal_places": 31,
    //                 "negred": true,
    //                 "lang": "zh-tw",
    //                 "custom_number_format": "[$-380A]dddd\\,\\ dd\" de \"mmmm\" de \"yyyy;@"
    //             },
    //             "style2": {
    //                 "fill":{"type":"gradient","color":["#FFFFFF"],"shading":1}
    //             }
    //         },
    //         "dataStyle": {"style1":["A1,B1"],"style2":["A2,B2","B3,B3"]},
    //         "colWidth": {"20": ["A,A", "B,C"], "30": ["D,F"]},
    //           "rowHeight": {"10": [1, 2], "15": [3, 4]}
    //     },
    //     {
    //         "name": "sheet2",
    //         "images": [{"path":"/tmp/1.png"}, {"path":"/tmp/2.png"}],
    //         "data": [["NUM1", "NUM2"],[1,2],[3,4]]
    //     }
    // ]
    excel.create('/home/admin/temp/test.xlsx', [{'name':'Sheet1', 'images':[{'path':'/temp/logo.png'}], 'style': {'style1':{'fill':{'type':'pattern','color':['#FFF8DC'],'pattern':3}}}, 'data': [['DEP', 'NUM'],['DE1', 10]], 'dataStyle': {'style1':['A2,B2']}}, {'name':'Sheet2', 'data':[['EMP']]}]);
    
    // read: Read data from xlsx file
    // params: dfspath<string>
    // return: table<array>
    var res excel.read('/home/admin/temp/test.xlsx')
    
  • memcache

    // load: Load class data to memory cache table
    // params: tableName<string>, type<string>, srouce<string>, indexes<multi-array>, lazyLoadData<bool>
    // return: None
    // type: mql | json | csv | ltsv | jsonfile | csvfile | ltsvfile
    // note: DFS file must be in the /etc/extend directory
    memcache.load('TESTCACHE', 'mql', '/testclasscache', [['key'],['group'],['msg','group']], false)
    memcache.load('TESTCACHE2', 'mql', "select key, msg, group from /testclasscache where group = 'G1'", [['msg','group']], false)
    memcache.load('TESTCACHE3', 'json', '[{"key":"K1","msg":"M","group":"G1"}]', [['key'],['msg','group']], false)
    memcache.load('TESTCACHE4', 'jsonfile', '/etc/extend/testcache.json', [['key'],['msg','group']], false)
    
    // reload: Force reload class data to memory cache table
    // params: tableName<string>
    // return: None
    memcache.reload('TESTCACHE')
    
    // remove: Remove table from memory cache
    // params: tableName<string>
    // return: None
    memcache.remove('TESTCACHE')
    
    // info: Get memory cache table info by tableName
    // params: tableName<string>
    // return: info<object>
    memcache.info('TESTCACHE')
    
    // query: Query memory cache by conditions
    // params: tableName<string>, where<string>, queryFields<string>, values<array>
    // return: result<array>
    // where: Sqlite sql expression
    // note: Load must be done before Query
    var res = memcache.query('TESTCACHE', "key = ?", 'key, group, msg', ['KEY1'])
    
    // reverseQuery: Reverse query memory cache by conditions
    // params: tableName<string>, where<string>, keys<table>, message<string>, greed<bool>, ignorecase<bool>
    // return: <result array>
    // where: Sqlite sql expression
    // note: Load must be done before Query
    var res = memcache.reverseQuery('TESTCACHE', "\"group\" = 'G1'", ['msg'], 'M', true, true)
    
    // list: Get memory cache table info list
    // params: None
    // return: list<list>
    memcache.list()
    
  • localcache

    // exec: Execute SQL statement
    // params: dbName<string>, sql<string>, values<any...>
    // return: None
    localcache.exec('testdb', 'CREATE TABLE IF NOT EXISTS person (id, name, age)');
    localcache.exec('testdb', 'INSERT INTO person (id, name, age) values (?, ?, ?)', 'ID1', 'Kate', 20);
    
    // query: Query SQL statement
    // params: dbName<string>, sql<string>, values<any...>
    // return: result<list>
    var res = localcache.query('testdb', 'SELECT * FROM person WHERE id = ?', 'ID1');
    
    // remove: Remove db from local cache
    // params: dbName<string>
    // return: None
    localcache.remove('testdb');
    
    // list: Get local cache db name list
    // params: None
    // return: names<list>
    localcache.list();
    
  • serverjs

    // exec: Execute ServerJS
    // params: jsPath<string>, input<string>
    // return: result<object>
    var res = serverjs.exec('/matrix/test/testrun2.js', 'Who are you');
    
    // execAsync: Asynchronous execution of ServerJS
    // params: jsPath<string>, input<string>
    // return: result<object>
    serverjs.execAsync('/matrix/test/testrun2.js', "It doesn't matter who you are");
    
    // runtime: Get running ServerJS
    // params: None
    // return: result<object>
    var res = serverjs.runtime();
    
    // interrupt: Interrupt running ServerJS
    // params: runids<int...>
    // return: None
    serverjs.interrupt(1,2);
    
    // stats: Get ServerJS stats info
    // params: None
    // return: result<object>
    var res = serverjs.stats();
    
  • sftp

    // upload: Upload dfs file to remote
    // params: user<string>, passwd<string>, privateKeyFile<string>, host<string>, port<int>, dfsFile<string>, uploadDir<string>
    // return: None
    sftp.upload('root', 'root123', '', '47.92.151.165', 22, '/matrix/test/testrun2.js', '/opt/matrix/var');
    
  • git

    // init: Repository list
    // params: None
    // return: list<array>
    var res = git.list();
    
    // init: Init repository
    // params: name<string>
    // return: None
    git.init('test');
    
    // addFile: Add file to repository
    // params: name<string>, relativeFilePath<string>, fileText<string>
    // return: None
    git.addFile('test', '/files/a.txt', 'Hello wold!');
    
    // commit: Commit changes
    // params: name<string>, msg<string>
    // return: None
    git.commit('test', 'Commit changes.');
    
    // createTag: Create tag
    // params: name<string>, tag<string>
    // return: None
    git.createTag('test', 'v1.0.0');
    
    // deleteTag: Delete tag
    // params: name<string>, tag<string>
    // return: None
    git.deleteTag('test', 'v1.0.0');
    
    // tags: Get tag list
    // params: name<string>
    // return: None
    var res = git.tags('test');
    
    // checkout: Checkout branch or tag
    // params: name<string>, branch<string>
    // return: None
    git.checkout('test', 'v1.0.0');
    
    // push: Push branch to remote branch
    // params: name<string>, branch<string>, remoteBranch<string>
    // return: None
    git.push('test', 'master', 'master');
    
    // runCommand: Run git command
    // params: name<string>, any...<values>
    // return: None
    git.runCommand('test', 'status');
    
    // readFile: Read file from repository
    // params: name<string>, relativeFilePath<string>
    // return: None
    var res = git.readFile('test', '/files/a.txt');
    
    // remove: Remove repository
    // params: name<string>
    // return: None
    var res = git.remove('test');
    
  • multitenant

    // dfsSync: Sync dfs to destination keyspace
    // params: destKeyspace<string>, filePath<string>
    // return: None
    multitenant.dfsSync('wecise2', '/test');
    



results matching ""

    No results matching ""