Menu

Trigger on threshold does not work with new metric

Jacopo D.
2025-02-21
2025-03-26
  • Jacopo D.

    Jacopo D. - 2025-02-21

    Hello everybody,
    As mentioned in my previous topic, I successfully created a new metric based on response time (see the code below).

    Now, the problem is that when I tried to create a new notification based on threshold 75 and 100, I did not receive anything. No results are shown in 'Last Executions'. Instead, other notifications, like the threshold for TTO, are working fine!

    Can anyone kindly help me figure out what I am missing ?

    (A little extra info: When I update the dictionary to change the field 'rt' to 'RT', the modification is not applied. However, if I change it directly in the source code, it works).

    New RT metric code (dependency: itop-service-mgmt/3.2.0)

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.2">
      <constants>
      </constants>
      <classes>
         <class id="SLT" _delta="must_exist">
          <fields>
            <field id="metric" xsi:type="AttributeEnum" _delta="must_exist">
              <values>
                <value id="rt">
                  <code>rt</code>
                </value>
              </values>
            </field>
          </fields>
        </class>
      </classes>
      <menus>
      </menus>
      <user_rights>
        <groups>
        </groups>
        <profiles>
        </profiles>
      </user_rights>
    </itop_design>
    

    Stop watch (redefine of user request, dependency "itop-request-mgmt-itil/3.2.0)":

                    <field id="rt" xsi:type="AttributeStopWatch" _delta="define">
                        <states>
                            <state id="assigned">assigned</state>
                        </states>
                        <working_time/>
                        <thresholds>
                            <threshold id="75">
                                <highlight>
                                    <code>warning</code>
                                    <persisent>false</persisent>
                                </highlight>
                                <actions/>
                            </threshold>
                            <threshold id="100">
                                <highlight>
                                    <code>critical</code>
                                    <persisent>false</persisent>
                                </highlight>
                                <actions>
                                    <action>
                                        <verb>ApplyStimulus</verb>
                                        <params>
                                            <param>ev_timeout</param>
                                        </params>
                                    </action>
                                </actions>
                            </threshold>
                        </thresholds>
                        <goal>ResponseTicketRT</goal>
                        <always_load_in_tables>true</always_load_in_tables>
                    </field>
                    <field id="rt_escalation_deadline" xsi:type="AttributeSubItem">
                        <target_attcode>rt</target_attcode>
                        <item_code>100_deadline</item_code>
                    </field>
                    <field id="sla_rt_passed" xsi:type="AttributeSubItem">
                        <target_attcode>rt</target_attcode>
                        <item_code>100_passed</item_code>
                    </field>
                    <field id="sla_rt_over" xsi:type="AttributeSubItem">
                        <target_attcode>rt</target_attcode>
                        <item_code>100_overrun</item_code>
                    </field>
    

    Method to recalcute the stopwatch every time there is an update on public log (same XML as the stopwatch):

                    <method id="AfterUpdate" _delta="define">
                        <static>false</static>
                        <access>protected</access>
                        <type>Overload-DBObject</type>
                        <code>
                            protected function AfterUpdate()
                            {
                            parent::AfterUpdate();
                            $oLog = $this->Get('public_log');
                            if ($oLog->GetModifiedEntry('html') != '') {
                            // Reimposta il campo rt_escalation_deadline al suo valore predefinito
                            $this->ResetStopWatch('rt');
                            // Cambia lo stato del ticket a "assigned"
                            if ($this->Get('status') != 'assigned') {
                            $this->ApplyStimulus('ev_assign');
                            }
                            }
                            }
                        </code>
                    </method>
    

    PHP function:

    <?php
    
    /**
     * Compute the Response Time of a ticket - null if the class 'SLT' does not exist
     */
    class ResponseTicketRT extends ResponseTicketSLT implements iMetricComputer
    {
        public static function GetDescription()
        {
            return "Time to response a ticket";
        }
    
        public function ComputeMetric($oObject)
        {
            $iRes = $this->ComputeSLT($oObject, 'rt');
            return $iRes;
        }
    }
    
     
  • Jacopo D.

    Jacopo D. - 2025-03-25

    Hello everyone,

    Is there anyone who could provide me with assistance or suggest any advices/tips/guides to solve the problem?

    Thanks.

     
  • Jacopo D.

    Jacopo D. - 2025-03-26

    Solved with a surprising solution:

    The stopwatch code must be at least 3 characters long; otherwise, the following query inside ormstopwatch.class.inc.php will fail:

    SELECT TriggerOnThresholdReached AS t WHERE t.target_class IN ('$sClassList') AND stop_watch_code MATCHES :stop_watch_code AND threshold_index = :threshold_index

    So, after changing 'rt' to 'rtx', notifications are now working fine too.

     

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.