How to find which source is using which credentials and the count of credentials for each source?

SaitejaN
Tera Contributor
 
1 ACCEPTED SOLUTION

James Behrens
Giga Guru

Just taking a swag.. Are you asking how do I find what affinities were associated to a credential? If so, I feel your pain. We have 60 mids for ITOM, affinities are made per IP per mid server that happened to pick up that discovery. We have dozens of credentials. Ugh. Looking through the affinities table is near on impossible.

 

If someone has a better way, I am all ears...

 

I use crazy background scripts like this for per credential:

var aff = new GlideRecord('dscy_credentials_affinity');
aff.addEncodedQuery('credential_idLIKEa5496c8793d70e90f6bbfb6a6aba10f2');
aff.query();

var aff_arr = [];
while (aff.next()) {
    if (aff_arr.indexOf(aff.ip_address.getValue()) == -1) {
        aff_arr.push(aff.ip_address.getValue());
    }
}

gs.print(aff_arr.length);

var ips = new GlideRecord('cmdb_ci_ip_address');
ips.addQuery('ip_address', 'IN', aff_arr);
ips.query();

var ci_arr = [];
while (ips.next()) {
    var ci = {};
    ci.name = ips.nic.cmdb_ci.getDisplayValue();
    ci.sys_class = ips.nic.cmdb_ci.sys_class_name.getValue();
    ci.sys_class = ips.nic.cmdb_ci.u_operating_system.getDisplayValue();
    ci.ipaddr = ips.ip_address.getValue();
    ci.ci_support = ips.nic.cmdb_ci.support_group.getDisplayValue();
    ci_arr.push(ci);
}

gs.print(JSON.stringify(ci_arr));

 

or this for per discovery to see what affinities were used

var dev = new GlideRecord('discovery_device_history');
// dev.addEncodedQuery('status=d9f6094093c826180dba36919dba1039^classified_as!=NULL');
dev.addQuery('status.number', 'DIS0015013');
dev.addNotNullQuery('classified_as');
dev.setLimit(10);
dev.query();

var cnt = dev.getRowCount();

gs.print(cnt);

// while(dev.next()){
// 	gs.print(dev.getDisplayValue());
// 	gs.print(dev.cmdb_ci.getDisplayValue());
// 	gs.print(dev.status.getDisplayValue());
// }

ci_arry = [];
while (dev.next()) {
    ci_arry.push(dev.cmdb_ci.sys_id.getValue());
}


// var ip_arry = [];
// while (dev.next()) {
//     ip_arry.push(dev.getDisplayValue());
//      gs.print(ips.nic.cmdb_ci.getDisplayValue() + ':' + ips.ip_address.getValue());
// }

var ips = new GlideRecord('cmdb_ci_ip_address');
ips.addQuery('nic.cmdb_ci', 'IN', ci_arry);
ips.query();

var ip_arry = [];
while (ips.next()) {
    ip_arry.push(ips.ip_address.getValue());
    //gs.print(ips.nic.cmdb_ci.getDisplayValue() + ':' + ips.ip_address.getValue());
}


var aff = new GlideRecord('dscy_credentials_affinity');
aff.addQuery('ip_address', 'IN', ip_arry);
aff.query();

var aff_arr = [];
var i = 0;
while (aff.next()) {

    // gs.info(aff.credential_id.getDisplayValue());
    if (aff_arr.indexOf(aff.credential_id.getDisplayValue()) == -1) {
        aff_arr.push(aff.credential_id.getDisplayValue());
        // gs.info('found an affinity for: {0} : {1}', aff.ip_address.getDisplayValue(), aff.credential_id);
    }
    i++;
}

var creds = new GlideRecord('discovery_credentials');
creds.addQuery('sys_id', 'IN', aff_arr);
creds.query();

var creds_arry = [];
while (creds.next()) {
    creds_arry.push(creds.getDisplayValue());
}

gs.print(JSON.stringify(creds_arry));

 

 

View solution in original post

4 REPLIES 4

Mark Manders
Mega Patron

Please elaborate.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

I am asking how to find credentials for ServiceNow and SG -GCP Discovery Sources.

James Behrens
Giga Guru

Just taking a swag.. Are you asking how do I find what affinities were associated to a credential? If so, I feel your pain. We have 60 mids for ITOM, affinities are made per IP per mid server that happened to pick up that discovery. We have dozens of credentials. Ugh. Looking through the affinities table is near on impossible.

 

If someone has a better way, I am all ears...

 

I use crazy background scripts like this for per credential:

var aff = new GlideRecord('dscy_credentials_affinity');
aff.addEncodedQuery('credential_idLIKEa5496c8793d70e90f6bbfb6a6aba10f2');
aff.query();

var aff_arr = [];
while (aff.next()) {
    if (aff_arr.indexOf(aff.ip_address.getValue()) == -1) {
        aff_arr.push(aff.ip_address.getValue());
    }
}

gs.print(aff_arr.length);

var ips = new GlideRecord('cmdb_ci_ip_address');
ips.addQuery('ip_address', 'IN', aff_arr);
ips.query();

var ci_arr = [];
while (ips.next()) {
    var ci = {};
    ci.name = ips.nic.cmdb_ci.getDisplayValue();
    ci.sys_class = ips.nic.cmdb_ci.sys_class_name.getValue();
    ci.sys_class = ips.nic.cmdb_ci.u_operating_system.getDisplayValue();
    ci.ipaddr = ips.ip_address.getValue();
    ci.ci_support = ips.nic.cmdb_ci.support_group.getDisplayValue();
    ci_arr.push(ci);
}

gs.print(JSON.stringify(ci_arr));

 

or this for per discovery to see what affinities were used

var dev = new GlideRecord('discovery_device_history');
// dev.addEncodedQuery('status=d9f6094093c826180dba36919dba1039^classified_as!=NULL');
dev.addQuery('status.number', 'DIS0015013');
dev.addNotNullQuery('classified_as');
dev.setLimit(10);
dev.query();

var cnt = dev.getRowCount();

gs.print(cnt);

// while(dev.next()){
// 	gs.print(dev.getDisplayValue());
// 	gs.print(dev.cmdb_ci.getDisplayValue());
// 	gs.print(dev.status.getDisplayValue());
// }

ci_arry = [];
while (dev.next()) {
    ci_arry.push(dev.cmdb_ci.sys_id.getValue());
}


// var ip_arry = [];
// while (dev.next()) {
//     ip_arry.push(dev.getDisplayValue());
//      gs.print(ips.nic.cmdb_ci.getDisplayValue() + ':' + ips.ip_address.getValue());
// }

var ips = new GlideRecord('cmdb_ci_ip_address');
ips.addQuery('nic.cmdb_ci', 'IN', ci_arry);
ips.query();

var ip_arry = [];
while (ips.next()) {
    ip_arry.push(ips.ip_address.getValue());
    //gs.print(ips.nic.cmdb_ci.getDisplayValue() + ':' + ips.ip_address.getValue());
}


var aff = new GlideRecord('dscy_credentials_affinity');
aff.addQuery('ip_address', 'IN', ip_arry);
aff.query();

var aff_arr = [];
var i = 0;
while (aff.next()) {

    // gs.info(aff.credential_id.getDisplayValue());
    if (aff_arr.indexOf(aff.credential_id.getDisplayValue()) == -1) {
        aff_arr.push(aff.credential_id.getDisplayValue());
        // gs.info('found an affinity for: {0} : {1}', aff.ip_address.getDisplayValue(), aff.credential_id);
    }
    i++;
}

var creds = new GlideRecord('discovery_credentials');
creds.addQuery('sys_id', 'IN', aff_arr);
creds.query();

var creds_arry = [];
while (creds.next()) {
    creds_arry.push(creds.getDisplayValue());
}

gs.print(JSON.stringify(creds_arry));

 

 

SaitejaN
Tera Contributor

Thank you