{ title: 'Invalid push objects configuration', description: 'This test will check if users are missing a push object, or if the refered push object does not exist', todo: 'Please ensure every user has a properly configured and existing push object\r\n', author: 'pla@innovaphone.com', schedule: '1h', commands: { evaluatedObjects: { cmd: "PBX0/ADMIN/mod_cmd_login.xml?cmd=show&user=*", cat: ["pbx"], }, config: { cmd: "cfg.txt", cat: ["pbx"] }, }, test: function(cmd, results) { const log = []; var success = true; Object.keys(results.evaluatedObjects).forEach(function(deviceId) { const pushObjects = []; const userWithSession = []; const pbxObjects = cmd.get_pbx_objects_from_config(results.config[deviceId]); pbxObjects.forEach(function(line) { if ( !/\(pbx=.*?<\/pseudo>\)/.test(line) && /\(pbx=.*?<\/sessions>\)/.test(line) ) { userWithSession.push(line.match(/\(h323=(.*?)\)/)[1]); } else if (/.*?<\/pseudo>/.test(line)) { pushObjects.push(line.match(/\(h323=(.*?)\)/)[1]); } }); const evalUserObjects = cmd.parse_xml(results.evaluatedObjects[deviceId], "user"); if (!evalUserObjects) return; evalUserObjects.forEach(function(obj) { // Has some pseudo tag && pseudo tag is not config template if (typeof obj.pseudo === 'undefined') return; if (typeof obj.pseudo["@type"] === 'undefined') return; if (typeof obj.pseudo["@push"] === 'undefined') return; if (typeof obj.pseudo["@cn"] === 'undefined') return; if (typeof obj.pseudo["@h323"] === 'undefined') return; if (obj.pseudo && obj.pseudo["@type"] !== "config") return; // Has either Softphone App || Phone App || A Session // Regex of stringified object to not rely on for loops if ( /"app":.*?{"@name":"(phone)"[^}]*?}.*?,/gm.test(JSON.stringify(obj)) || /"app":.*?{"@name":"(softphone)"[^}]*?}.*?,/gm.test(JSON.stringify(obj)) || userWithSession.includes(obj["@h323"]) ) { if(!obj.pseudo && !obj["@push"]) buildErrorMsg("User: "+obj["@cn"]+" / no push object configured", deviceId); } if (obj["@push"] && !pushObjects.includes(obj["@push"])) buildErrorMsg("User: "+obj["@cn"]+" / Push Object: "+obj["@push"]+" does not exist", deviceId); }); }); return { success: success, msg: success ? "" : "User(s) missing valid push object", log: log } function buildErrorMsg(msg, deviceId) { const device = cmd.get_device(deviceId); success = false; log.push(device.product+" / "+device.hwId+" / "+device.name+" / "+msg); }; } }