Clarity Service Management

BOP-LOGIN Spel Method to get session information

By Giedrius Bekintis posted 01-04-2016 04:25 PM

  

I was looking for the method to get information about all current sessions in SDM. As I understand bop-login is the process responsible for handling of the sessions. From trigger definition in ldap.maj i have learned that it is possible to execute methods defined there. Examination of boplgn.exe revealed that there is a number of other methods defined there, and one of them is called session_info that returns a lot of interesting information like:

count of active sessions, session id's, userid, current user role and etc.

 

Here is an example of the code that you can use to execute using bop_cmd

 

void login2()
{
int i,j,count;
send_wait(0, (object)("@|BOP-LOGIN|validate_user|0"), "session_info");
   if (msg_error()) { 
    printf("Error %s",msg[0]);
   }
   else{
    j=0;
    count = msg[0];

    printf("Sessions found: %s \n",count);
    for(i=0;i<count;i++){
    j=i*12+1;

    printf("======= %s ==============\n", msg[j+3]);
    printf("Session ID: %s \n", msg[j]);
    printf("Webengine: %s \n", msg[j+1]);
    printf("Domsrv: %s \n", msg[j+2]);
    printf("Userid: %s \n", msg[j+3]);
    printf("User persistent_id: %s \n", msg[j+4]);
    printf("Current user role: %s \n", msg[j+5]);
    printf("Licensed? %s \n", msg[j+6]);
    printf("Session type: %s \n", msg[j+7]);
    //All session types canS be found in session_type object here are some of them
    //"Web browser session" ,"1"
    //"SOAP Web services session" ,"3"
    //"Server utility session" ,"4"
    //"REST Web Services Session" ,"10"
    printf("Web Service login policy: %s \n", msg[j+8]);
    printf("Session status: %s \n", msg[j+9]);//4 - incative 2 - active 3-timed-out
    printf("Login time stamp: %s \n", msg[j+10]);
    printf("Logout time stamp: %s \n", msg[j+11]);
    printf("\n\n\n");
    }

   }
}

And here is batch file content to execute it

bop_cmd -u ServiceDesk -f %~dp0/log.frg login2("")

 

 

 

I also have plans to explore bop_login methods further. If someone have any info on this topic please share.

16 comments
2 views

Comments

10-30-2018 08:44 AM

Thanks Jerome.

10-30-2018 08:38 AM

Hi Daniel and thanks for the update

 

in my 17.1 in AA

I have to modify from line 231 as below for this to work correctly:

 

 

                    for (zi_j=1; zi_j<zi_session_count*13+1; zi_j+=13) {
                         zs_session_id            = z_identify_session_id((int)msg[zi_j]);
                         zs_webengine             = z_identify_webengine((string)msg[zi_j+1]);
                         zs_domsrvr               = z_identify_domsrvr((string)msg[zi_j+2]);
                         zs_userid                = z_identify_userid((string)msg[zi_j+3]);
                         zs_username              = z_identify_cnt((string)msg[zi_j+5]);
                         zs_user_persid           = z_identify_user_persid((string)msg[zi_j+5]);
                         zs_user_role             = z_identify_user_role((string)msg[zi_j+6]);
                         zs_licensed              = z_identify_licensed((int)msg[zi_j+7], zs_format);
                         zs_session_type          = z_identify_session_type((int)msg[zi_j+8]);
                         zs_webservice_policy     = z_identify_webservice_policy((int)msg[zi_j+9]);
                         zs_session_status        = z_identify_session_status((int)msg[zi_j+10]);
                         zs_login_time_stamp      = z_identify_time_stamp((long)msg[zi_j+11], zs_format);
                         zs_logout_time_stamp     = z_identify_time_stamp((long)msg[zi_j+12], zs_format);

 

No idea what is now msg[zi_j+4] as this always return empty to me.

Not that the casting may not be necessary but was part of my troubleshooting and always good to be sure to pass correct data type to your function.

 

Hope this help

/J

07-11-2017 07:57 PM

New version available!!!

Enjoy!

 

 

string z_get_sessions_list(...)
{
     ////////////////////////////////////////////////////////////////////////
     // Method:               z_get_sessions_list
     // Author:               Daniel Becker Bighelini
     // Created:               11/07/2017
     // Modified by:          Daniel Becker Bighelini
     // Modified:          21/07/2017
     // Description:          List sessions of users in all servers.
     // Usage:               z_get_sessions_list([options])
     // Options:
     //                          -h            (help)
     //                          -c            (CSV output)
     //                          -d?           (CSV output with delimiter. DEFAULT: ';' semicolon)
     //                          -e            (CSV output with double double quotes)
     //                          -j            (JSON output)
     //                          -n            (informal report output. DEFAULT)
     //                          -s            (mode SILENT)
     //                          -u            (no headers)
     //                          -v            (verbose)
     //                          -userid:?     (userid)
     //                         -userpersid:? (user persistent_id)
     //                         -host:?       (host)
     //                         -session:?    (session)
     //                         -webengine:?  (webengine)
     //                         -licensed:?   (licensed)
     //                         -role:?       (user role)
     //                         -type:?       (session type)
     //                         -status:?     (session status)
     // Default output:
     //                         ===========================================
     //                         Session ID         : 944876194
     //                         Host               : SERVER1
     //                         Webengine          : agent_intf#6500
     //                         Domsrv             : domsrvr
     //                         Userid             : servicedesk
     //                         Username           : servicedesk
     //                         User persistent_id : cnt:5D60C9AB5AB023438704EEB9EA89DEC9
     //                         User role          : Administrador
     //                         Licensed           : Yes
     //                         Session type       : Web Services (SOAP Web services session)
     //                         Webservice policy  : PADRÃO (Política padrão de acesso a serviços da web)
     //                         Session status     : Active
     //                         Login time stamp   : 07/11/2017 16:49:00
     //                         Logout time stamp  :
     //                         ===========================================
     // CSV output:
     //                         SESSIONID,HOST,WEBENGINE,DOMSRVR,USERID,USERNAME,USER_PERSID,USER_ROLE,LICENSED,SESSION_TYPE,WEBSERVICE_POLICY,SESSION_STATUS,LOGIN_TIME_STAMP,LOGOUT_STAMP
     //                         1828872505,SIWDES1300,web:local,domsrvr,procergs-daniel-bighelini,Daniel Becker Bighelini,cnt:ED4D469F18BC4943B940AB934D020C6D,Administrador Procergs,Yes,Web Client (Web browser session),None,Timed-out,07/11/2017 17:02:26,
     //
     // JSON output:          [{
     //                         "session_id"               :     91980526,
     //                         "host"                         :     "SIWDES1300",
     //                         "webengine"                    :     "bop_cmd-#2064",
     //                         "domsrv"                    :     "domsrvr:04",
     //                         "userid"                    :     "servicedesk",
     //                         "username"                    :     "servicedesk",
     //                         "user_persistent_id"     :     "cnt:5D60C9AB5AB023438704EEB9EA89DEC9",
     //                         "user_role"                    :     "Administrador",
     //                         "licensed"                    :     true,
     //                         "session_type"               :     "Utility (Server utility session)",
     //                         "webservice_policy"          :     "None",
     //                         "session_status"          :     "Active",
     //                         "login_time_stamp"          :     "2018-07-19T14:06:40Z",
     //                         "logout_time_stamp"          :     null
     //                         }]
     ////////////////////////////////////////////////////////////////////////////
     // Redefine Spel execution limit
     set_ilimit(2147483648);
    
     int zi_debug, zi_i, zi_j;
     string zs_method, zs_msg, zs_param, zs_header, zs_quote, zs_delim, zs_format, zs_silent, zs_verbose, zs_output,
             zs_param_userid, zs_param_userpersid, zs_param_host, zs_param_session, zs_param_webengine,
             zs_param_domsrvr, zs_param_licensed, zs_param_role, zs_param_type, zs_param_status;
    
     zi_debug = 0;
     zs_method = "z_get_sessions_list";
     zs_output = ""; zs_param = ""; zs_header = ""; zs_quote = ""; zs_delim = ""; zs_format = ""; zs_silent = "";
     zs_verbose = ""; zs_output = ""; zs_param_userid = ""; zs_param_userpersid = ""; zs_param_host = "";
     zs_param_session = ""; zs_param_webengine = ""; zs_param_domsrvr = ""; zs_param_licensed = "";
     zs_param_role = ""; zs_param_type = ""; zs_param_status = "";
     zs_msg = "";
    
     // Debug mode
     if (zi_debug > 0) {
          logf(SIGNIFICANT, "%s Number of arguments : %d", zs_method, argc);
          for (zi_i=0; zi_i<argc; zi_i++) {
               logf(SIGNIFICANT, "%s ARG #%d : %s", zs_method, zi_i, argv[zi_i]);
          }
     } else {
          //logf(SIGNIFICANT, "%s", zs_method);
     }
    
     ///////////////////////////////////////////////////////////////////////////////////////
     // Start of code
     for (zi_i=0; zi_i<argc; zi_i++) { // consolidate options
          zs_param = downcase(argv[zi_i]);
          zs_param = gsub(zs_param, '@GTR@', '>'); // compatibility batch
          zs_param = gsub(zs_param, '@LSS@', '<'); // compatibility batch
         
          if (zi_debug > 0) logf(SIGNIFICANT, "%s param = '%s'", zs_method, zs_param);
          if (zs_param == '-c') {
               zs_format = 'CSV';
          } else if (sindex(zs_param, '-d') == 0 && sindex(zs_param, '-domsrvr:') == -1) {
               zs_delim = substr(zs_param, sindex(zs_param, '-d')+2);
          } else if (zs_param == '-e') {
               zs_quote = format('""');
          } else if (zs_param == '-h') {
               z_show_help();
               return;
          } else if (zs_param == '-n') {
               zs_format = 'DEFAULT';
          } else if (zs_param == '-j') {
               zs_format = 'JSON';
          } else if (zs_param == '-s') {
               zs_silent = 'true';
          } else if (zs_param == '-u') {
               zs_header = 'false';
          } else if (zs_param == '-v') {
               zs_verbose = 'true';
               zi_debug = 1;
          } else if (sindex(zs_param, '-userid:') == 0) {
               zs_param_userid = substr(zs_param, sindex(zs_param, '-userid:')+8);
          } else if (sindex(zs_param, '-userpersid:') == 0) {
               zs_param_userpersid = substr(zs_param, sindex(zs_param, '-userpersid:')+12);
          } else if (sindex(zs_param, '-host:') == 0) {
               zs_param_host = substr(zs_param, sindex(zs_param, '-host:')+6);
          } else if (sindex(zs_param, '-session:') == 0) {
               zs_param_session = substr(zs_param, sindex(zs_param, '-session:')+9);
          } else if (sindex(zs_param, '-webengine:') == 0) {
               zs_param_webengine = substr(zs_param, sindex(zs_param, '-webengine:')+11);
          } else if (sindex(zs_param, '-domsrvr:') == 0) {
               zs_param_domsrvr = substr(zs_param, sindex(zs_param, '-domsrvr:')+9);
          } else if (sindex(zs_param, '-licensed:') == 0) {
               zs_param_licensed = substr(zs_param, sindex(zs_param, '-licensed:')+10);
          } else if (sindex(zs_param, '-role:') == 0) {
               zs_param_role = substr(zs_param, sindex(zs_param, '-role:')+6);
          } else if (sindex(zs_param, '-type:') == 0) {
               zs_param_type = substr(zs_param, sindex(zs_param, '-type:')+6);
          } else if (sindex(zs_param, '-status:') == 0) {
               zs_param_status = substr(zs_param, sindex(zs_param, '-status:')+8);
          } else {
               z_show_help(zs_param);
               return;
          }
     }

     // Redefine variables when is empty/null
     if (is_empty(zs_format)) zs_format = 'DEFAULT';
     if (is_empty(zs_header)) zs_header = 'true';
     if (is_empty(zs_silent)) zs_silent = 'false';
     if (is_empty(zs_verbose)) zs_verbose = 'false';
     if (is_empty(zs_delim)) zs_delim = ';';
     if (is_empty(zs_quote)) zs_quote = '"';
    
     // Show parameters received
     if (zi_debug > 0) {
          logf(SIGNIFICANT, "%s Parameters received", zs_method);
          logf(SIGNIFICANT, "%s FORMAT    : '%s'", zs_method, zs_format);
          logf(SIGNIFICANT, "%s HEADER    : '%s'", zs_method, zs_header);
          logf(SIGNIFICANT, "%s DELIMITER : '%s'", zs_method, zs_delim);
          logf(SIGNIFICANT, "%s QUOTE     : '%s'", zs_method, zs_quote);
          logf(SIGNIFICANT, "%s SILENT    : '%s'", zs_method, zs_silent);
          logf(SIGNIFICANT, "%s VERBOSE   : '%s'", zs_method, zs_verbose);
          logf(SIGNIFICANT, "%s USERID    : '%s'", zs_method, zs_param_userid);
          logf(SIGNIFICANT, "%s USERPERSID: '%s'", zs_method, zs_param_userpersid);
          logf(SIGNIFICANT, "%s HOST      : '%s'", zs_method, zs_param_host);
          logf(SIGNIFICANT, "%s SESSION   : '%s'", zs_method, zs_param_session);
          logf(SIGNIFICANT, "%s WEBENGINE : '%s'", zs_method, zs_param_webengine);
          logf(SIGNIFICANT, "%s DOMSRVR   : '%s'", zs_method, zs_param_domsrvr);
          logf(SIGNIFICANT, "%s LICENSED  : '%s'", zs_method, zs_param_licensed);
          logf(SIGNIFICANT, "%s ROLE      : '%s'", zs_method, zs_param_role);
          logf(SIGNIFICANT, "%s TYPE      : '%s'", zs_method, zs_param_type);
          logf(SIGNIFICANT, "%s STATUS    : '%s'", zs_method, zs_param_status);
     }
    
     // Generating list of servers
     string zs_wc;
     zs_wc = "linked = 1"; // Only configured servers
     if (zi_debug > 0) logf(SIGNIFICANT, "%s Generating list of servers with where clause '%s'...", zs_method, zs_wc);
     send_wait(0, top_object(), "call_attr", "usp_servers", "sync_fetch", "RLIST_STATIC", zs_wc, -1, 0);
     if (msg_error()) {
          zs_msg = format("%s ERROR 'sync_fetch' with where clause '%s': '%s'", zs_method, zs_wc, msg[0]);
          logf(ERROR, zs_msg);
          return zs_msg;
     }
     object zo_server_list;
     zo_server_list = msg[0];
     int zi_server_count;
     zi_server_count = msg[1];
    
     // Querying servers
     string zs_server[100], zs_server_type[100];
     if (zi_debug > 0) logf(SIGNIFICANT, "%s Querying %d servers...", zs_method, zi_server_count);
     if (zi_server_count > 0) {
          for (zi_i=0; zi_i<zi_server_count; zi_i++) {
               send_wait(0, zo_server_list, "dob_by_index", "DEFAULT", zi_i, zi_i);
               if (msg_error()) {
                    zs_msg = format("%s ERROR 'dob_by_index': '%s'", zs_method, msg[0]);
                    logf(ERROR, zs_msg);
                    return zs_msg;
               }
               object zo_server;
               zo_server = msg[0];
               zs_server[zi_i] = zo_server.local_host;
               zs_server_type[zi_i] = zo_server.server_type.sym;
               if (zi_debug > 0) logf(SIGNIFICANT, "%s %d/%d Server found: %s (%s)", zs_method, zi_i+1, zi_server_count, zs_server[zi_i], zs_server_type[zi_i]);
          }

          // Querying sessions
          int zi_session_total, zi_session_match;
          zi_session_total = 0;
          zi_session_match = 0;
          for (zi_i=0; zi_i<zi_server_count; zi_i++) {
               if (zi_debug > 0) logf(SIGNIFICANT, "%s Querying sessions info...", zs_method);
               send_wait(0, (object) format("%s|BOP-LOGIN|validate_user|0", zs_server[zi_i]), "session_info");
               if (msg_error()) {
                    zs_msg = format("%s ERROR 'validate_user' in host '%s': '%s'", zs_method, zs_server[zi_i], msg[0]);
                    logf(ERROR, zs_msg);
                    return zs_msg;

               } else {
                    int zi_session_count;
                    zi_session_count = msg[0];
                    if (zi_debug > 0) logf(SIGNIFICANT, "%s %s sessions found: %d", zs_method, zs_server[zi_i], zi_session_count);
              
                    string     zs_host, zs_session_id, zs_webengine, zs_domsrvr, zs_userid, zs_username, zs_user_persid, zs_user_role, zs_licensed,
                              zs_session_type, zs_webservice_policy, zs_session_status, zs_login_time_stamp, zs_logout_time_stamp;
                    zs_host = zs_server[zi_i];
                   
                    for (zi_j=1; zi_j<zi_session_count*12+1; zi_j+=12) {
                         zs_session_id               = z_identify_session_id(msg[zi_j]);
                         zs_webengine               = z_identify_webengine(msg[zi_j+1]);
                         zs_domsrvr                    = z_identify_domsrvr(msg[zi_j+2]);
                         zs_userid                    = z_identify_userid(msg[zi_j+3]);
                         zs_username                    = z_identify_cnt(msg[zi_j+4]);
                         zs_user_persid               = z_identify_user_persid(msg[zi_j+4]);
                         zs_user_role               = z_identify_user_role(msg[zi_j+5]);
                         zs_licensed                    = z_identify_licensed(msg[zi_j+6], zs_format);
                         zs_session_type               = z_identify_session_type(msg[zi_j+7]);
                         zs_webservice_policy     = z_identify_webservice_policy(msg[zi_j+8]);
                         zs_session_status          = z_identify_session_status(msg[zi_j+9]);
                         zs_login_time_stamp          = z_identify_time_stamp(msg[zi_j+10], zs_format);
                         zs_logout_time_stamp     = z_identify_time_stamp(msg[zi_j+11], zs_format);
                        
                         if (!is_empty(zs_param_host) && downcase(zs_param_host) != downcase(zs_host)) continue;
                         if (!is_empty(zs_param_session) && downcase(zs_param_session) != downcase(zs_session_id)) continue;
                         if (!is_empty(zs_param_webengine) && downcase(zs_param_webengine) != downcase(zs_webengine)) continue;
                         if (!is_empty(zs_param_domsrvr) && downcase(zs_param_domsrvr) != downcase(zs_domsrvr)) continue;
                         if (!is_empty(zs_param_userid) && downcase(zs_param_userid) != downcase(zs_userid)) continue;
                         if (!is_empty(zs_param_userpersid) && downcase(zs_param_userpersid) != downcase(zs_user_persid)) continue;
                         if (!is_empty(zs_param_role) && downcase(zs_param_role) != downcase(zs_user_role)) continue;
                         if (!is_empty(zs_param_licensed) && downcase(zs_param_licensed) != downcase(zs_licensed)) continue;
                         if (!is_empty(zs_param_type) && downcase(zs_param_type) != downcase(zs_session_type)) continue;
                         if (!is_empty(zs_param_status) && downcase(zs_param_status) != downcase(zs_session_status)) continue;
                        
                         zi_session_match++;
                        
                         if (zs_format == 'CSV') {
                              zs_output += format('%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n',
                                        zs_quote, zs_session_id, zs_quote, zs_delim, zs_quote, zs_host, zs_quote, zs_delim,
                                        zs_quote, zs_webengine, zs_quote, zs_delim, zs_quote, zs_domsrvr, zs_quote, zs_delim,
                                        zs_quote, zs_userid, zs_quote, zs_delim, zs_quote, zs_username, zs_quote, zs_delim,
                                        zs_quote, zs_user_persid, zs_quote, zs_delim, zs_quote, zs_user_role, zs_quote, zs_delim,
                                        zs_quote, zs_licensed, zs_quote, zs_delim, zs_quote, zs_session_type, zs_quote, zs_delim,
                                        zs_quote, zs_webservice_policy, zs_quote, zs_delim, zs_quote, zs_session_status, zs_quote, zs_delim,
                                        zs_quote, zs_login_time_stamp, zs_quote, zs_delim, zs_quote, zs_logout_time_stamp, zs_quote);
                             
                         } else if (zs_format == 'DEFAULT') {
                              zs_output += format("%s\n", z_separator());
                              zs_output += format("Session ID        : %s\n", zs_session_id);
                              zs_output += format("Host              : %s\n", zs_host);
                              zs_output += format("Webengine         : %s\n", zs_webengine);
                              zs_output += format("Domsrv            : %s\n", zs_domsrvr);
                              zs_output += format("Userid            : %s\n", zs_userid);
                              zs_output += format("Username          : %s\n", zs_username);
                              zs_output += format("User persid       : %s\n", zs_user_persid);
                              zs_output += format("User role         : %s\n", zs_user_role);
                              zs_output += format("Licensed          : %s\n", zs_licensed);
                              zs_output += format("Session type      : %s\n", zs_session_type);
                              zs_output += format("Webservice policy : %s\n", zs_webservice_policy);
                              zs_output += format("Session status    : %s\n", zs_session_status);
                              zs_output += format("Login time stamp  : %s\n", zs_login_time_stamp);
                              zs_output += format("Logout time stamp : %s\n", zs_logout_time_stamp);
                              zs_output += format("%s\n\n", z_separator());

                         } else if (zs_format == 'JSON') {
                              zs_output += '{' +
                                             format('"session_id": %s,', zs_session_id) +
                                             format('"host": "%s",', zs_host) +
                                             format('"webengine": "%s",', zs_webengine) +
                                             format('"domsrv": "%s",', zs_domsrvr) +
                                             format('"userid": "%s",', zs_userid) +
                                             format('"username": "%s",', zs_username) +
                                             format('"user_persid": "%s",', zs_user_persid) +
                                             format('"user_role": "%s",', zs_user_role) +
                                             format('"licensed": "%s",', zs_licensed) +
                                             format('"session_type": "%s",', zs_session_type) +
                                             format('"webservice_policy": "%s",', zs_webservice_policy) +
                                             format('"session_status": "%s",', zs_session_status) +
                                             format('"login_time_stamp": "%s",', zs_login_time_stamp) +
                                             format('"logout_time_stamp": "%s"', zs_logout_time_stamp) +
                                             '}';
                              zs_output += ',';
                         }
                    } // End of For
                    zi_session_total += zi_session_count;
                   
               } // End of If
          } // End of For
         
          // Formatting output report
          if (zi_session_match > 0) {
               if (zs_format == 'CSV' && zs_header == 'true') { // Format CSV
                    // Defining headers report
                    zs_output = format("%sSESSIONID%s%s%sHOST%s%s%sWEBENGINE%s%s%sDOMSRVR%s%s%sUSERID%s%s%sUSERNAME%s%s%sUSER_PERSID%s%s%sUSER_ROLE%s%s%sLICENSED%s%s%sSESSION_TYPE%s%s%sWEBSERVICE_POLICY%s%s%sSESSION_STATUS%s%s%sLOGIN_TIME_STAMP%s%s%sLOGOUT_TIME_STAMP%s\n%s",
                              zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim,
                              zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim,
                              zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim,
                              zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_delim,
                              zs_quote, zs_quote, zs_delim, zs_quote, zs_quote, zs_output);
              
               } else if (zs_format == 'JSON') { // Format JSON
                    zs_output = gsub(zs_output, '""', 'null');
                    zs_output = gsub(zs_output, '"true"', 'true');
                    zs_output = gsub(zs_output, '"false"', 'false');
                    if (substr(zs_output, strlen(zs_output)-1) == ",") zs_output = substr(zs_output, 0, strlen(zs_output)-1);
                    zs_output = format("[%s]", zs_output);
               }
         
               if (zs_silent != 'true') printf("%s", zs_output);
          }
         
          if (zi_debug > 0) {
               logf(SIGNIFICANT, "%s TOTAL of sessions found: %d", zs_method, zi_session_total);
               logf(SIGNIFICANT, "%s TOTAL of sessions match: %d", zs_method, zi_session_match);
          }
    
     } else {
          zs_msg = format("%s ERROR: No server found!", zs_method);
          logf(ERROR, zs_msg);
          return zs_msg;
     }
    
     return zs_output;
     // End of code
     ///////////////////////////////////////////////////////////////////////////////////////
}


string z_separator()
{
     return "========================================================";
}


string z_identify_session_id(int zi_session_id)
{
     return (string) zi_session_id;
}


string z_identify_webengine(string zs_webengine)
{
     if (!is_empty(zs_webengine)) {
          return zs_webengine;
     } else {
          return NULL;
     }
}


string z_identify_domsrvr(string zs_domsrvr)
{
     if (!is_empty(zs_domsrvr)) {
          return zs_domsrvr;
     } else {
          return NULL;
     }
}


string z_identify_user_role(string zs_user_role)
{
     if (!is_empty(zs_user_role)) {
          return zs_user_role;
     } else {
          return NULL;
     }
}


string z_identify_user_persid(string zs_user_persid)
{
     if (!is_empty(zs_user_persid)) {
          return zs_user_persid;
     } else {
          return NULL;
     }
}


string z_identify_userid(string zs_userid)
{
     if (!is_empty(zs_userid)) {
          return zs_userid;
     } else {
          return NULL;
     }
}


string z_identify_licensed(int zi_licensed, ...)
{
     if (argv[1] != "JSON") {
          if (zi_licensed == 1) {
               return 'Yes';
          } else {
               return 'No';
          }
     } else {
          if (zi_licensed == 1) {
               return 'true';
          } else {
               return 'false';
          }
     }
}


string z_identify_session_type(int zi_session_type)
{
     string zs_session_sym, zs_session_description;
     zs_session_sym = expand(format("&{%s = session_type.id->sym}", zi_session_type));
     zs_session_description = expand(format("&{%s = session_type.id->description}", zi_session_type));
    
     if (!is_empty(zs_session_sym)) {
          return format("%s (%s)", zs_session_sym, zs_session_description);
     } else {
          return format("Unknow (%d)", zi_session_type);
     }
}


string z_identify_webservice_policy(int zi_webservice_policy)
{
     if (zi_webservice_policy == 0) return 'None';
     string zs_policy_sym, zs_policy_description;
     zs_policy_sym = expand(format("&{%d = sapolicy.id->sym}", zi_webservice_policy));
     zs_policy_description = expand(format("&{%d = sapolicy.id->description}", zi_webservice_policy));
    
     if (!is_empty(zs_policy_sym)) {
          return format("%s (%s)", zs_policy_sym, zs_policy_description);
     } else {
          return format("Unknow (%d)", zi_webservice_policy);
     }
}


string z_identify_session_status(int zi_session_status)
{
     switch (zi_session_status) {
          case 4: return "Inactive"; break;
          case 3: return "Timed-out"; break;
          case 2: return "Active"; break;
          default: return format("Unknow (%d)", zi_session_status);
     }
}


string z_identify_time_stamp(long zl_duration, ...)
{
     if (zl_duration != 0 && argv[1] != "JSON") {
          return (string) (date) zl_duration;
     } else {
          if (zl_duration == 0) {
               return NULL;
          } else {
               string zs_date;
               zs_date = z_formatDate((string) (date) zl_duration, 'MM/DD/YYYY HH:mm:ss', 'YYYY-MM-DDTHH:mm:ss', 0, 'z_identify_time_stamp');
               return zs_date;
          }
     }
}


string z_identify_cnt(string zs_persid)
{
     string zs_cnt_combo_name;
     zs_cnt_combo_name = expand(format("&{%s = cnt.persistent_id->combo_name}", zs_persid));
    
     if (!is_empty(zs_cnt_combo_name)) {
          return zs_cnt_combo_name;
     } else {
          return NULL;
     }
}


void z_show_help(...)
{
     if (argc>0) {
          logf(ERROR, "z_get_sessions_list: illegal option -- %s", gsub(argv[0], '-', ''));
     }
     printf("Usage: bop_cmd [-u servicedesk] -f z_session_list.spl \"z_get_sessions_list([options])\"\n");
     printf(" [ -h            (help) ]\n");
     printf(" [ -c            (CSV output) ]\n");
     printf(" [ -d?           (CSV output with delimiter. DEFAULT: ';' semicolon) ]\n");
     printf(" [ -e            (CSV output with double double quotes) ]\n");
     printf(" [ -j            (JSON output) ]\n");
     printf(" [ -n            (informal report output. DEFAULT) ]\n");
     printf(" [ -s            (mode SILENT) ]\n");
     printf(" [ -u            (no headers) ]\n");
     printf(" [ -v            (verbose) ]\n");
     printf("\n");
     printf("Advanced options\n");
     printf(" [ -userid:?     (userid) ]\n");
     printf(" [ -userpersid:? (user persistent_id) ]\n");
     printf(" [ -host:?       (host) ]\n");
     printf(" [ -session:?    (session) ]\n");
     printf(" [ -webengine:?  (webengine) ]\n");
     printf(" [ -licensed:?   (licensed) ]\n");
     printf(" [ -role:?       (user role) ]\n");
     printf(" [ -type:?       (session type) ]\n");
     printf(" [ -status:?     (session status) ]\n");
}


string z_formatDate(string zs_date_in, string zs_format_in, string zs_format_out, int zi_depurar, string zs_metodo)
{
     ////////////////////////////////////////////////////////////////////////
     // Metodo:               z_formatDate
     // Autor:               Daniel Becker Bighelini
     // Criado em:          16/02/2017
     // Modificado por:     Daniel Becker Bighelini
     // Modificado em:     18/07/2017
     //
     // Descricao:          Formata uma string de data de acordo com o formato de saida de data definido.
     //
     // Parametros:
     //          arg[0]     :     (string) zs_date_in          Define uma string de data de entrada
     //          arg[1]     :     (string) zs_format_in     Define o formato da data de entrada
     //          arg[2]     :     (string) zs_format_out     Define o formato da data de saida
     //          arg[3]     :     (int)       zi_depurar          Define o nivel de depuracao da funcao (0=Desligado, 1=Log resumido, 2=Log detalhado, 3=Super detalhado)
     //          arg[4]     :     (string) zs_metodo          Define o nome do metodo que esta chamando este metodo
     //
     // Exemplos:
     //                         z_formatDate('16-2-2017 15:35', 'DD-MM-YYYY HH:mm', 'MM/DD/YYYY HH:mm:ss', 1, 'teste');     // Retorna '02/16/2017 15:35:00'
     //                         z_formatDate('16022017153547', 'DDMMYYYYHHmmss', 'MM/DD/YYYY HH:mm:ss', 1, 'teste');     // Retorna '02/16/2017 15:35:47'
     //                         z_formatDate('16/02/2017 15:35:47', 'DD/MM/YYYY HH:mm:ss', 'YYYYMMDDHHmm', 1, 'teste');     // Retorna '201702161535'
     //
     ////////////////////////////////////////////////////////////////////////
     zs_metodo += " z_formatDate";

    ///////////////////////////////////////////////////////////////////////////////////////
    // Inicio do codigo

     if (zi_depurar > 1) {
          logf(SIGNIFICANT, "%s Formato de entrada: '%s'", zs_metodo, zs_format_in);
          logf(SIGNIFICANT, "%s Formato de saida  : '%s'", zs_metodo, zs_format_out);
          logf(SIGNIFICANT, "%s Data de entrada   : '%s'", zs_metodo, zs_date_in);
     }
    
     // ABORTA a execucao em alguns cenarios
     if (zs_format_in == zs_format_out || is_empty(zs_date_in)) return zs_date_in;
    
     // Para identificar dia, mes, ano, hora, minuto e segundo
     int zi_i, zi_j;
     string zs_date_out, zs_fmt, zs_char_actual, zs_char_next, zs_char_format_in, zs_char_format_out, zs_char_date_in;
     string zsa_array_format_in[150], zsa_array_format_out[150], zsa_array_date_in[150];
     int zi_pos_format_in, zi_pos_date_in, zi_pos_format_out;

     // Inicializa as variaveis
     for (zi_i=0; zi_i<15; zi_i++) {
          zsa_array_format_in[zi_i] = "";
          zsa_array_format_out[zi_i] = "";
          zsa_array_date_in[zi_i] = "";
     }
     zs_date_out = "";
     zi_pos_format_in = 0;
     zi_pos_date_in = 0;
     zi_pos_format_out = 0;

     // Percorre cada caractere do FORMATO DE ENTRADA
     for (zi_i=0; zi_i<strlen(zs_format_in); zi_i++) {
          zs_char_actual = substr(zs_format_in, zi_i, 1);
          zs_char_next = substr(zs_format_in, zi_i+1, 1);
          zsa_array_format_in[zi_pos_format_in] += zs_char_actual;
          if (zi_depurar > 3) {
               logf(SIGNIFICANT, "%s CHAR ACTUAL: '%s'", zs_metodo, zs_char_actual);
               logf(SIGNIFICANT, "%s CHAR NEXT  : '%s'", zs_metodo, zs_char_next);
          }
          if (zs_char_next != zs_char_actual) {
               if (zi_depurar > 2) logf(SIGNIFICANT, "%s FORMAT IN  #%d='%s'", zs_metodo, zi_pos_format_in, zsa_array_format_in[zi_pos_format_in]);
               zi_pos_format_in++;
          }
     }
    
     // Percorre cada caractere da DATA DE ENTRADA
     for (zi_i=0; zi_i<strlen(zs_date_in); zi_i++) {
          zs_char_actual = substr(zs_date_in, zi_i, 1);
          zs_char_next = substr(zs_date_in, zi_i+1, 1);
          zsa_array_date_in[zi_pos_date_in] += zs_char_actual;
          if (zi_depurar > 3) {
               logf(SIGNIFICANT, "%s CHAR ACTUAL: '%s'", zs_metodo, zs_char_actual);
               logf(SIGNIFICANT, "%s CHAR NEXT  : '%s'", zs_metodo, zs_char_next);
          }
          if (z_isNumber(zs_char_next) != z_isNumber(zs_char_actual) || strlen(zsa_array_date_in[zi_pos_date_in]) == strlen(zsa_array_format_in[zi_pos_date_in])) {
               if (zi_depurar > 2) logf(SIGNIFICANT, "%s DATE IN    #%d='%s'", zs_metodo, zi_pos_date_in, zsa_array_date_in[zi_pos_date_in]);
               zi_pos_date_in++;
          }
     }
    
     // Percorre cada caractere do FORMATO DE SAIDA
     for (zi_i=0; zi_i<strlen(zs_format_out); zi_i++) {
          zs_char_actual = substr(zs_format_out, zi_i, 1);
          zs_char_next = substr(zs_format_out, zi_i+1, 1);
          zsa_array_format_out[zi_pos_format_out] += zs_char_actual;
          if (zi_depurar > 3) {
               logf(SIGNIFICANT, "%s CHAR ACTUAL: '%s'", zs_metodo, zs_char_actual);
               logf(SIGNIFICANT, "%s CHAR NEXT  : '%s'", zs_metodo, zs_char_next);
          }
          if (zs_char_next != zs_char_actual) {
               if (zi_depurar > 2) logf(SIGNIFICANT, "%s FORMAT OUT #%d='%s'", zs_metodo, zi_pos_format_out, zsa_array_format_out[zi_pos_format_out]);
               zi_pos_format_out++;
          }
     }
    
     // Transforma a DATA DE ENTRADA na DATA DE SAIDA obedecendo o FORMATO DE SAIDA
     zs_date_out = "";
     for (zi_i=0; zi_i<zi_pos_format_out; zi_i++) {
          zs_char_format_out = substr(zsa_array_format_out[zi_i], 0, 1);
          if (zi_depurar > 3) logf(SIGNIFICANT, "%s CHAR OUT ATUAL: '%s'", zs_metodo, zs_char_format_out);
         
          if (z_isAlpha(zs_char_format_out)) { // Se for uma LETRA (dmyhms...)
               for (zi_j=0; zi_j<zi_pos_format_in; zi_j++) {
                    zs_char_format_in = substr(zsa_array_format_in[zi_j], 0, 1);
                    if (zi_depurar > 3) logf(SIGNIFICANT, "%s CHAR IN  ACTUAL: '%s'", zs_metodo, zs_char_format_in);
                    if (zs_char_format_in == zs_char_format_out) {
                         zs_char_date_in = substr(zsa_array_date_in[zi_j], 0, 1);
                         zs_date_out += z_formatNumber(zsa_array_date_in[zi_j], strlen(zsa_array_format_out[zi_i]), zi_depurar, zs_metodo);
                         break;
                    }
                    if (zi_j == zi_pos_format_in-1) { // Caso nao encontre
                         //zs_date_out += z_formatNumber("0", strlen(zsa_array_format_out[zi_i]), zi_depurar, zs_metodo);
                         zs_date_out += z_formatNumber(zs_char_format_out, strlen(zsa_array_format_out[zi_i]), zi_depurar, zs_metodo);
                    }
               }
              
          } else {
               zs_date_out += zs_char_format_out; // Se for um separador (' ', '/', ':', ...)
          }
     }
     if (zi_depurar > 1) logf(SIGNIFICANT, "%s Data de saida     : '%s'", zs_metodo, zs_date_out);

     return zs_date_out;
     // Fim do codigo
    ///////////////////////////////////    
}


string z_formatNumber(string zs_number_in, int zi_length_max, int zi_depurar, string zs_metodo)
{
     ////////////////////////////////////////////////////////////////////////
     // Metodo:               z_formatNumber
     // Autor:               Daniel Becker Bighelini
     // Criado em:          16/02/2017
     // Modificado por:     Daniel Becker Bighelini
     // Modificado em:     18/07/2017
     //
     // Descricao:          Formata uma string de numero de acordo com um numero maximo de caracteres definido.
     //
     // Parametros:
     //          arg[0]     :     (string) zs_number_in     Define uma string de numero de entrada
     //          arg[1]     :     (int)    zi_length_max     Define o tamanho maximo da string de numero
     //          arg[2]     :     (int)       zi_depurar          Define o nivel de depuracao da funcao (0=Desligado, 1=Log resumido, 2=Log detalhado, 3=Super detalhado)
     //          arg[3]     :     (string) zs_metodo          Define o nome do metodo que esta chamando este metodo
     //
     // Exemplos:
     //                         z_formatNumber('1975', 2, 1, 'teste'); // Retorna '75'
     //                         z_formatNumber('15', 4, 1, 'teste'); // Retorna '0015'
     //                         z_formatNumber('', 3, 1, 'teste'); // Retorna '000'
     //
     ////////////////////////////////////////////////////////////////////////
     zs_metodo += " z_formatNumber";

    ///////////////////////////////////////////////////////////////////////////////////////
    // Inicio do codigo
     if (zi_depurar > 3) {
          logf(SIGNIFICANT, "%s Numero de entrada: '%s'", zs_metodo, zs_number_in);
          logf(SIGNIFICANT, "%s Tamanho da saida : %d", zs_metodo, zi_length_max);
     }

     string zs_fmt, zs_number_out;
     if (is_empty(zs_number_in)) zs_number_in = "0";

     if (strlen(zs_number_in) < zi_length_max) {
          zs_fmt = format("%%0%dd", zi_length_max);
          zs_number_out = format(zs_fmt, zs_number_in);
     } else {
          zs_number_out = substr(zs_number_in, strlen(zs_number_in) - zi_length_max);
     }

     if (zi_depurar > 3) logf(SIGNIFICANT, "%s Numero de saida  : '%s'", zs_metodo, zs_number_out);
     return zs_number_out;
     // Fim do codigo
    ///////////////////////////////////    
}


int z_isNumber(string s)
{
     ///////////////////////////////////////////////////////////////////////////////////////
     // Inicio do codigo
     if (sindex(s, '^[0-9]*$') == 0) {
          return 1;
     } else {
          return 0;
     }
     // Fim do codigo
     ///////////////////////////////////////////////////////////////////////////////////////
}


int z_isAlpha(string s)
{
     ///////////////////////////////////////////////////////////////////////////////////////
     // Inicio do codigo
     if (sindex(s, '^[aA-zZ]*$') == 0) {
          return 1;
     } else {
          return 0;
     }
     // Fim do codigo
     ///////////////////////////////////////////////////////////////////////////////////////
}

04-10-2017 12:01 PM

Little improvement discovered recently.
As this script is regular SPEL script, execution could be terminated due to ilimit excision, but manual defining ilimit prevents this:

void login2() {
     set_ilimit(2147483648);
     int i, j, count;
     ...

12-20-2016 09:41 AM

I have attached zip file, simply copy files to sdm server and run them, license count on the end will show licensed concurent sessions

12-20-2016 09:30 AM

Gutis jmayer Thanks for the Info Guys!!! I dont know if is possible to add the "Concurrent Number", similar to the information that is gather with "pdm_logstat -f lic_mgr.c 300".

 

Thanks

03-04-2016 03:36 AM

I look at it a second round and realized that this may hard to go trough the output may you have a large number of session open.

I have quickly adapted again to be able to choose your output type by using -n (previous behavior) or -c (csv type)  that you can open in exell for more easy view and eventual manipulation (grouping, count, etc). Not really optimized code but quickly do the trick.

 

Hope this help. feel free to improve and share tot he community

/J

 

new bat file content:

 

@ECHO OFF
REM use -n for normal output and -c for csv like output to be used in exell

bop_cmd -u ServiceDesk -f log.frg login2("-c") > dom_session_log.csv
EXIT

 

 

below the new code:

 

void login2(...) 
{

string zfileType;
zfileType = "-n";
if(argv[0] == "-c" ){
zfileType = "-c";
}else if(is_null(argv[0])){
zfileType = "-n";
}

int i,j,count;
int zLic;
int zSess;
int zSts;
string zloginStr;
date zLoginEpoch;
string zlogoutStr;
date zLogoutEpoch;
 
send_wait(0, (object)("@|BOP-LOGIN|validate_user|0"), "session_info"); 
   if (msg_error()) {   
    printf("Error %s",msg[0]); 
   } 
   else{ 
    j=0; 
    count = msg[0];

  if (zfileType == "-c"){
    printf("Sessions id:,Webengine:,Domsrv:,Userid:,User persistent_id:,Current user role:,Licensed?,Session type:,Web Service login policy:,Session status:,Login time stamp:,Logout time stamp:\n"); 
   
for(i=0;i<count;i++){ 
    j=i*12+1; 
 
    printf("%s,", msg[j]); 
    printf("%s,", msg[j+1]); 
    printf("%s,", msg[j+2]); 
    printf("%s,", msg[j+3]); 
    printf("%s,", msg[j+4]); 
    printf("%s,", msg[j+5]);

zLic=msg[j+6];

if(zLic == 0){
  printf("No,");
  }else{
   if (zLic == 1){
   printf("Yes,");
   }else{
   printf("%s,", msg[j+6]);
    }
   }
 
zSess=msg[j+7];
switch (zSess) {
  case 1 : printf("Web browser session,");
    break;
  case 2 : printf("Java client session,");
    break;
  case 3 : printf("SOAP Web services session,");
    break;
  case 4 : printf("Server utility session,");
    break;
  case 5 : printf("Portal session,");
    break;
  case 6 : printf("nowledge Chat session,");
    break;
  case 7 : printf("Mail Server session,");
    break;
  case 8 : printf("Custom Application session,");
    break;
  case 9 : printf("PDA Client session,");
    break;
  case 10 : printf("REST Web Services Session,");
    break;
  default : printf("%s,", msg[j+7]);
}

     printf("%s,", msg[j+8]);

zSts=msg[j+9];

if(zSts == 2){
  printf("Active,");
}else{
  if(zSts == 3){
   printf("Timed-out,");
  }else{
   if(zSts == 4){
    printf("Inactive,");
   }else{
    printf("%s,", msg[j+9]);
   }
   }
}

if(msg[j+10] > 0){
  zLoginEpoch=msg[j+10];
  zLoginStr=(string)zLoginEpoch;
  printf("%s,", zLoginStr);
}else{
  printf("%s,", msg[j+10]);
  }
 
    if(msg[j+11] > 0){
  zLogoutEpoch=msg[j+11];
  zLogoutStr=(string)zLogoutEpoch;
 
  printf("%s\n", zLogoutStr);
}else{
  printf("%s\n", msg[j+11]);
  }
    } 
   }else if (zfileType == "-n"){
    printf("Sessions found: %s \n",count); 
   
for(i=0;i<count;i++){ 
    j=i*12+1; 
 
    printf("======= %s ==============\n", msg[j+3]); 
    printf("Session ID: %s \n", msg[j]); 
    printf("Webengine: %s \n", msg[j+1]); 
    printf("Domsrv: %s \n", msg[j+2]); 
    printf("Userid: %s \n", msg[j+3]); 
    printf("User persistent_id: %s \n", msg[j+4]); 
    printf("Current user role: %s \n", msg[j+5]);

zLic=msg[j+6];

if(zLic == 0){
  printf("Licensed? No \n");
  }else{
   if (zLic == 1){
   printf("Licensed? Yes \n");
   }else{
   printf("Licensed? %s \n", msg[j+6]);
    }
   }

zSess=msg[j+7];
switch (zSess) {
  case 1 : printf("Session type: Web browser session \n");
    break;
  case 2 : printf("Session type: Java client session \n");
    break;
  case 3 : printf("Session type: SOAP Web services session \n");
    break;
  case 4 : printf("Session type: Server utility session \n");
    break;
  case 5 : printf("Session type: Portal session \n");
    break;
  case 6 : printf("Session type: Knowledge Chat session \n");
    break;
  case 7 : printf("Session type: Mail Server session \n");
    break;
  case 8 : printf("Session type: Custom Application session \n");
    break;
  case 9 : printf("Session type: PDA Client session \n");
    break;
  case 10 : printf("Session type: REST Web Services Session \n");
    break;
  default : printf("Session type: %s \n", msg[j+7]);
}

     printf("Web Service login policy: %s \n", msg[j+8]);

zSts=msg[j+9];

if(zSts == 2){
  printf("Session status: Active \n");
}else{
  if(zSts == 3){
   printf("Session status: Timed-out \n");
  }else{
   if(zSts == 4){
    printf("Session status: inactive \n");
   }else{
    printf("Session status: %s \n", msg[j+9]);
   }
   }
}

if(msg[j+10] > 0){
  zLoginEpoch=msg[j+10];
  zLoginStr=(string)zLoginEpoch;
  printf("Login time stamp: %s \n", zLoginStr);
}else{
  printf("Login time stamp: %s \n", msg[j+10]);
  }
 
    if(msg[j+11] > 0){
  zLogoutEpoch=msg[j+11];
  zLogoutStr=(string)zLogoutEpoch;
 
  printf("Logout time stamp: %s \n", zLogoutStr);
}else{
  printf("Logout time stamp: %s \n", msg[j+11]);
  }
 
    printf("\n\n");
   }
}
}
}

03-02-2016 11:46 AM

Just read that one Nice job Gutis!

I have taken the initiative  to enhance a little to output the string and datetime vs the code/epoch time as based on your inline code comment and the session_type table

Thanks again for the smart idea

 

void login2() 

int i,j,count; 
send_wait(0, (object)("@|BOP-LOGIN|validate_user|0"), "session_info"); 
   if (msg_error()) {   
    printf("Error %s",msg[0]); 
   } 
   else{ 
    j=0; 
    count = msg[0]; 
 
    printf("Sessions found: %s \n",count); 
    for(i=0;i<count;i++){ 
    j=i*12+1; 
 
    printf("======= %s ==============\n", msg[j+3]); 
    printf("Session ID: %s \n", msg[j]); 
    printf("Webengine: %s \n", msg[j+1]); 
    printf("Domsrv: %s \n", msg[j+2]); 
    printf("Userid: %s \n", msg[j+3]); 
    printf("User persistent_id: %s \n", msg[j+4]); 
    printf("Current user role: %s \n", msg[j+5]);

int zLic;
zLic=msg[j+6];

if(zLic == 0){
  printf("Licensed? No \n");
  }else{
   if (zLic == 1){
   printf("Licensed? Yes \n");
   }else{
   printf("Licensed? %s \n", msg[j+6]);
    }
   }

int zSess;
zSess=msg[j+7];
switch (zSess) {
  case 1 : printf("Session type: Web browser session \n");
    break;
  case 2 : printf("Session type: Java client session \n");
    break;
  case 3 : printf("Session type: SOAP Web services session \n");
    break;
  case 4 : printf("Session type: Server utility session \n");
    break;
  case 5 : printf("Session type: Portal session \n");
    break;
  case 6 : printf("Session type: Knowledge Chat session \n");
    break;
  case 7 : printf("Session type: Mail Server session \n");
    break;
  case 8 : printf("Session type: Custom Application session \n");
    break;
  case 9 : printf("Session type: PDA Client session \n");
    break;
  case 10 : printf("Session type: REST Web Services Session \n");
    break;
  default : printf("Session type: %s \n", msg[j+7]);
}

     printf("Web Service login policy: %s \n", msg[j+8]);

int zSts;
zSts=msg[j+9];

if(zSts == 2){
  printf("Session status: Active \n");
}else{
  if(zSts == 3){
   printf("Session status: Timed-out \n");
  }else{
   if(zSts == 4){
    printf("Session status: inactive \n");
   }else{
    printf("Session status: %s \n", msg[j+9]);
   }
   }
}

if(msg[j+10] > 0){

  string zloginStr;

  date zLoginEpoch;

  zLoginEpoch=msg[j+10];

  zLoginStr=(string)zLoginEpoch;

  printf("Login time stamp: %s \n", zLoginStr);

}else{

  printf("Login time stamp: %s \n", msg[j+10]);

  }

 

    if(msg[j+11] > 0){

  string zlogoutStr;

  date zLogoutEpoch;

  zLogoutEpoch=msg[j+11];

  zLogoutStr=(string)zLogoutEpoch;

 

  printf("Logout time stamp: %s \n", zLogoutStr);

}else{

  printf("Logout time stamp: %s \n", msg[j+11]);

  }

 

 

 
    printf("\n\n"); 
    } 
   } 
}

 

02-18-2016 10:33 AM

Yes it takes time to find how to use daemon methods

02-18-2016 10:23 AM

Interesting information

 

I have not yet played around with any methods in that daemon, but like you say the methods are defined so it comes down to figuring out the parameters to pass and the results coming from that call.

 

I have done some limited testing with other daemons and their methods though, completely unrelated, but you'll see the similarities:

 

send_wait(0, (object)("@|arpur_srvr_arcpur_obj|0"),"start_arcpur", rule_name, hours);

send_wait(0, (object)("@|arpur_srvr_arcpur_obj|0"),"stop_arcpur", rule_name);

 

and have had some limited results calling the PDM_RPC daemon as well.

02-11-2016 04:56 PM

pdm_webstat -D

can give you IP adresses for the users loged via web interface, but session list will not include information for webservices, bop_cmd and other sessions

02-11-2016 04:31 PM

Sorry, Gutis… is working now. It was a copy/paste error.

 

Just a detail… where you found info about this options for send_wait send_wait(0, (object)("@|BOP-LOGIN|validate_user|0"), "session_info");

We need to obtain additionally the session ip address, and validate this for a list of users.

 

We notice too that the user running this command displays always a session type 4, we assume this is because of CMD command executed.

 

Thanks for your suggestions.

02-11-2016 04:02 PM

Don't have a clue why it is not working. I have copied above code to c:\ca\sdm\tmp\log.frg and executed

bop_cmd -u ServiceDesk -f log.frg login("")

from this directory, here is the output:

Maybe you can do same and place screenshot

02-11-2016 02:26 PM

It is necessary to apply  this?

 

https://communities.ca.com/docs/DOC-231156624

 

Now with files in the same \bin directory script return is null or empty.

 

Thanks for your help.

 

Regards,

JOHN

02-11-2016 12:34 PM

If you use bat file it must be located on the same category as frg file, if you do this from command line you must execute this command from the same directory where frg file resides othervise you need to specify full path to frg file

02-11-2016 12:30 PM

Could you please clarify about where this script must be created (Could be created in ../site/mods/majic). When execute bop_cmd -u ServiceDesk -f %~dp0/log.frg login2("") this error appears...

 

Unable to open script file :%~dp0/log.frg (No such file or directory (2))

Error parsing file %~dp0/log.frg

 

Any suggestion?

 

Regards,

JOHN