Menu

Automated changes through a script - is there a way to set a user for the activity log?

2025-10-31
2025-10-31
  • Jacques Dancause

    Hi there, this may be a weird question, but we've noticed a sort of 'Bug'.

    We have scripts to backfill certain fields in our data that may be inaccurate or unfilled. For example, we have a UUID field for each for assets. We have a script to run to update all the existing assets without UUIDs, and it works well, however...

    We've noticed that the Activity Log/Panel inaccurately shows the user who updated the record. It will always show the current logged in user as the user who did the change, regardless of who's logged in:

    example1

    In this picture, the current user appears as the one who did the changes to UUID, but that is false, the changes were executed through a script from the server terminal.

    This causes our users to get confused, so we started looking into why it was happening.

    When investigating the priv_change table, which holds these changes, we see that the user_id and userinfo fields are blank:

    example2

    So my question is, is there a way to programmatically set a userid for these changes? I'm using the DBObject methods to read and set this data. We would like to be able to create a user for these automatic updates, so that our endusers don't experience the bug when there is no user associated to the change.

    Here are the script contents:

    <?php
    
    /*
    Make sure you are in the web/ folder, and then run this command, changing the class name as an argument:
    
    php "scripts/php-scripts/backfilluuid.php" FunctionalCI
    */
    
    if (!isset($argv) || count($argv) < 2) {
      echo 'No argument provided - please provide the class name as an argument';
      die();
    }
    
    $className = $argv[1];
    
    require_once 'approot.inc.php';
    require_once APPROOT . '/application/application.inc.php';
    require_once APPROOT . '/application/itopwebpage.class.inc.php';
    require_once APPROOT . '/application/wizardhelper.class.inc.php';
    require_once APPROOT . '/application/startup.inc.php';
    
    $oFilter = new DBObjectSearch($className);
    $oSet = new DBObjectSet($oFilter);
    $oObjects = $oSet->ToArray();
    
    foreach ($oObjects as $key => $aObject) {
      $UUIDv4 = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i';
    
      if (!preg_match($UUIDv4, $aObject->Get('ods_uuid'))) {
        $aObject->Set('ods_uuid', ODSHelper::UUIDv4());
      }
    
      $aObject->DBUpdate();
    }
    ?>
    
     

    Last edit: Jacques Dancause 2025-10-31
  • Jacques Dancause

    Solved! I found it in the core itop code. It's CMDBObject::SetTrackInfo and SetTrackUserId.

    example

    example2

     
    👍
    1

    Last edit: Jacques Dancause 2025-10-31

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.