How often are PDI login records updated?

Simon Hendery
Tera Patron

I logged in today (directly from the PDI URL, not via the developer portal) but I see that's not reflected in the records yet:

 

pdi.PNG

 

I know PDI management is such a mess right now, but does anyone have a definitive answer to how often these records are updated? My hunch is it's a scheduled job, can anyone confirm?

 

Just trying to avoid having to replace my PDI for the 5th time this month because it gets reclaimed for "inactivity".

1 ACCEPTED SOLUTION

l457
Kilo Patron

If you check the script execution history on your pdi you should see this script being executed by a maint service user. It seems to gather telemetry on instance usage like last login (event) and last update/insert/delete (sys_update_xml) of an application artefact. I'd suspect that's all that is needed, logging in and making a configuration of any sort. I haven't had any issues with inactivity myself rather other sorts of issues but I tend to request a fresh instance on the regular anyway.

Spoiler
var propertyName= "glide.appcreator.company.code";
var activityEncodedQuery= "type!=System Property^sys_updated_on<=javascript&colon;gs.daysAgoEnd(-1)^sys_updated_by!=system^sys_updated_byNOT LIKE@snc^type!=Password Reset Process^ORtype=NULL^ORDERBYDESCsys_updated_on";
var instance= "80548fff47eacbd021f3e676706d43c9";
var instanceClassName= "dev_instance";
var obj = {};
obj.appCreatorCode = '';
obj.lastActivity = '';
obj.appCount = 0;
obj.instanceId = '';
obj.instanceName = '';
obj.hostname = '';
obj.dbhost = '';
obj.currentVersion = '';
obj.offering = '';

var answer = [];
var instanceRgr = new GlideRecord('sys_properties');
instanceRgr.addQuery('name', propertyName);
instanceRgr.query();
if (instanceRgr.next()) {
    obj.appCreatorCode = instanceRgr.getValue('value');
}

instanceRgr = new GlideRecord('sys_update_xml');
instanceRgr.addEncodedQuery(activityEncodedQuery);
instanceRgr.setLimit(1);
instanceRgr.query();
if (instanceRgr.next()) {
    obj.lastActivity = instanceRgr.getValue('sys_updated_on');
}

var instanceEvent = new GlideRecord("sysevent");
instanceEvent.addEncodedQuery("name=login^user_nameNOT LIKE@snc");
instanceEvent.orderByDesc("sys_created_on");
instanceEvent.setLimit(1);
instanceEvent.query();
if (instanceEvent.next()) {
    obj.last_logged_in = instanceEvent.getValue('sys_created_on');
}

// DB node info from sys_cluster_node_stats
var stateGr = new GlideRecord('sys_cluster_state');
stateGr.addQuery('status', 'online');
stateGr.addNotNullQuery('node_stats');
stateGr.setLimit(1);
stateGr.query();

if (stateGr.next()) {
    var nodeStatsId = stateGr.getValue('node_stats');
    var statsGr = new GlideRecord('sys_cluster_node_stats');
    if (statsGr.get(nodeStatsId)) {
        var stats = statsGr.getValue('stats');
        if (stats) {
            var xmlDoc = new XMLDocument(stats);
            obj.instanceId = String(xmlDoc.getNodeText('/xmlstats/instance_id'));
            obj.instanceName = String(xmlDoc.getNodeText('/xmlstats/instance_name'));
            obj.hostname = String(xmlDoc.getNodeText('/xmlstats/servlet.hostname'));
            var rawDbUrl = String(xmlDoc.getNodeText('/xmlstats/db.url'));
            obj.dbhost = rawDbUrl;
            obj.dbPort = '';
            if (rawDbUrl && rawDbUrl !== "null") {
                var dbMatch = rawDbUrl.match(/^jdbc:\w+:\/\/([^:\/]+)(?::(\d+))?/);
                if (dbMatch) {
                    obj.dbhost = dbMatch[1]; // e.g. db160037.aus191.service-now.com
                    obj.dbPort = dbMatch[2] || ''; // e.g. 3327
                }
            }
            obj.currentVersion = String(xmlDoc.getNodeText('/xmlstats/instance_current_version'));
            obj.offering = String(xmlDoc.getNodeText('/xmlstats/glide.offering'));
        }
    }
}

answer.push(obj);
var SNJSON = JSON, writer;

writer = GlideTransaction.get().getResponse().getWriter();

if (typeof answer !== 'undefined') {
    writer.write(new SNJSON().encode(answer));
}

writer.flush();
writer.close();

View solution in original post

2 REPLIES 2

l457
Kilo Patron

If you check the script execution history on your pdi you should see this script being executed by a maint service user. It seems to gather telemetry on instance usage like last login (event) and last update/insert/delete (sys_update_xml) of an application artefact. I'd suspect that's all that is needed, logging in and making a configuration of any sort. I haven't had any issues with inactivity myself rather other sorts of issues but I tend to request a fresh instance on the regular anyway.

Spoiler
var propertyName= "glide.appcreator.company.code";
var activityEncodedQuery= "type!=System Property^sys_updated_on<=javascript&colon;gs.daysAgoEnd(-1)^sys_updated_by!=system^sys_updated_byNOT LIKE@snc^type!=Password Reset Process^ORtype=NULL^ORDERBYDESCsys_updated_on";
var instance= "80548fff47eacbd021f3e676706d43c9";
var instanceClassName= "dev_instance";
var obj = {};
obj.appCreatorCode = '';
obj.lastActivity = '';
obj.appCount = 0;
obj.instanceId = '';
obj.instanceName = '';
obj.hostname = '';
obj.dbhost = '';
obj.currentVersion = '';
obj.offering = '';

var answer = [];
var instanceRgr = new GlideRecord('sys_properties');
instanceRgr.addQuery('name', propertyName);
instanceRgr.query();
if (instanceRgr.next()) {
    obj.appCreatorCode = instanceRgr.getValue('value');
}

instanceRgr = new GlideRecord('sys_update_xml');
instanceRgr.addEncodedQuery(activityEncodedQuery);
instanceRgr.setLimit(1);
instanceRgr.query();
if (instanceRgr.next()) {
    obj.lastActivity = instanceRgr.getValue('sys_updated_on');
}

var instanceEvent = new GlideRecord("sysevent");
instanceEvent.addEncodedQuery("name=login^user_nameNOT LIKE@snc");
instanceEvent.orderByDesc("sys_created_on");
instanceEvent.setLimit(1);
instanceEvent.query();
if (instanceEvent.next()) {
    obj.last_logged_in = instanceEvent.getValue('sys_created_on');
}

// DB node info from sys_cluster_node_stats
var stateGr = new GlideRecord('sys_cluster_state');
stateGr.addQuery('status', 'online');
stateGr.addNotNullQuery('node_stats');
stateGr.setLimit(1);
stateGr.query();

if (stateGr.next()) {
    var nodeStatsId = stateGr.getValue('node_stats');
    var statsGr = new GlideRecord('sys_cluster_node_stats');
    if (statsGr.get(nodeStatsId)) {
        var stats = statsGr.getValue('stats');
        if (stats) {
            var xmlDoc = new XMLDocument(stats);
            obj.instanceId = String(xmlDoc.getNodeText('/xmlstats/instance_id'));
            obj.instanceName = String(xmlDoc.getNodeText('/xmlstats/instance_name'));
            obj.hostname = String(xmlDoc.getNodeText('/xmlstats/servlet.hostname'));
            var rawDbUrl = String(xmlDoc.getNodeText('/xmlstats/db.url'));
            obj.dbhost = rawDbUrl;
            obj.dbPort = '';
            if (rawDbUrl && rawDbUrl !== "null") {
                var dbMatch = rawDbUrl.match(/^jdbc:\w+:\/\/([^:\/]+)(?::(\d+))?/);
                if (dbMatch) {
                    obj.dbhost = dbMatch[1]; // e.g. db160037.aus191.service-now.com
                    obj.dbPort = dbMatch[2] || ''; // e.g. 3327
                }
            }
            obj.currentVersion = String(xmlDoc.getNodeText('/xmlstats/instance_current_version'));
            obj.offering = String(xmlDoc.getNodeText('/xmlstats/glide.offering'));
        }
    }
}

answer.push(obj);
var SNJSON = JSON, writer;

writer = GlideTransaction.get().getResponse().getWriter();

if (typeof answer !== 'undefined') {
    writer.write(new SNJSON().encode(answer));
}

writer.flush();
writer.close();

Simon Hendery
Tera Patron

Thanks @l457 - very helpful!