<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Possible Bug with HOOK:AlarmStateChange on Alarm Creation]]></title><description><![CDATA[<p dir="auto">I was able to get the external alerting to work with OpsGenie finally and I think I discovered a bug in the Alarm generation.</p>
<p dir="auto">I am using the following code inside <em>HOOK:AlarmStateChange</em> </p>
<pre><code>sub main()
{
    eventserver = FindNodeObject($node, 100);
    global alarmstate = $alarm-&gt;state;
    global eventname = $alarm-&gt;eventName;
    global sourceobj = FindObject($alarm-&gt;sourceObject);
    global nameobj = sourceobj-&gt;guid;

    trace(0, &quot;Alarm State&quot; . alarmstate . &quot; Alarm:&quot; . eventname . nameobj);
    switch(alarmstate)
    {
/* Alarm State is Outstanding */
        case &quot;0&quot;:
            break;
/* Alarm State is Acknowledged */
        case &quot;1&quot;:
            PostEvent(eventserver, &quot;Xms_Alarm_Ack&quot;,&quot;ACKALARM&quot;, eventname . nameobj);
            break;
/* Alarm State is Resolved */
        case &quot;2&quot;:
            PostEvent(eventserver, &quot;Xms_Alarm_Resolve&quot;,&quot;RSLVALARM&quot;, eventname . nameobj);
            break;
/* Alarm State is Sticky Acknowledged */
        case &quot;17&quot;:
            PostEvent(eventserver, &quot;Xms_Alarm_StickyAck&quot;,&quot;SACKALARM&quot;, eventname . nameobj);
            break;
    }
}
</code></pre>
<p dir="auto">I originally had code for state 3 ( terminated ). This is where the bug seems to occur.<br />
When the Alarm is created <em>HOOK:AlarmStateChange</em> runs. This is not a big deal as that allows us to call scripts when an event is created as it should have a state of <strong>0</strong>. I noticed via the trace() function that some of the alarms were being created with a state of <strong>3</strong> instead of a state of <strong>0</strong>.</p>
<p dir="auto"><em>Currently we have an EPP that uses a server action to send a CURL request to the OpsGenie API for alert generation. We have Opsgenie integrated directly with Teams, and Jira for ticket management. I would be happy to post a guide on how to do this if anybody else wants to know how we implemented it.</em></p>
<p dir="auto">The code for state 3 ( terminated ) created an event &quot;Xms_Alarm_Term&quot;. This event would be processed by the EPP and use a server action to send a CURL request to OpsGenie to close the alert. The practical implications of the alarm being created with a state of 3 is that the alert is created in OpsGenie and Closed in Opsgenie at exactly the same moment.</p>
<p dir="auto">I suspect the problem is in alarm.cpp -&gt; Copy constructor.</p>
<p dir="auto"><div class="card col-md-9 col-lg-6 position-relative link-preview p-0">



<a href="https://github.com/netxms/netxms/blob/master/src/server/core/alarm.cpp" title="netxms/src/server/core/alarm.cpp at master · netxms/netxms">
<img src="https://opengraph.githubassets.com/19819498d6dcdcaef5d7f0855802bb674e3b85c6ba27571a1e4850ee3b00c2c1/netxms/netxms" class="card-img-top not-responsive" style="max-height: 15rem;" alt="Link Preview Image" onerror="this.parentElement.remove()" />
</a>



<div class="card-body">
<h5 class="card-title">
<a class="text-decoration-none" href="https://github.com/netxms/netxms/blob/master/src/server/core/alarm.cpp">
netxms/src/server/core/alarm.cpp at master · netxms/netxms
</a>
</h5>
<p class="card-text line-clamp-3">NetXMS - Open Source network and infrastructure monitoring and management - netxms/src/server/core/alarm.cpp at master · netxms/netxms</p>
</div>
<a href="https://github.com/netxms/netxms/blob/master/src/server/core/alarm.cpp" class="card-footer text-body-secondary small d-flex gap-2 align-items-center lh-2">



<img src="https://github.githubassets.com/favicons/favicon.svg" alt="favicon" class="not-responsive overflow-hiddden" style="max-width: 21px; max-height: 21px;" onerror="this.remove()"/>



<p class="d-inline-block text-truncate mb-0">GitHub <span class="text-secondary">(github.com)</span></p>
</a>
</div></p>
<p dir="auto">I could be wrong, but it appears that code is part of the alarm constructor that duplicates alarms if the event occurs again. I believe the reason this happens is the line (<em>378</em> )</p>
<pre><code>m_state = src-&gt;m_state;
</code></pre>
<p dir="auto">That code appears to set the new alarm state as the state of the source alarm. This is only an issue if the source alarm is terminated as it creates a new copy of the alarm with a state of <strong>3</strong>.</p>
<p dir="auto">I could very well be wrong about this, but it makes sense in my head.</p>
]]></description><link>https://forum.netxms.org/topic/7674/possible-bug-with-hook-alarmstatechange-on-alarm-creation</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 08:37:24 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/7674.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 May 2023 14:23:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Possible Bug with HOOK:AlarmStateChange on Alarm Creation on Tue, 13 Jun 2023 15:58:54 GMT]]></title><description><![CDATA[<p dir="auto">One possibility that I see is out of order execution of hook scripts which is theoretically possible. Server schedules execution of hook script in background thread pool, passing copy of alarm in its current state to the script. It is possible that due to database problems thread pool was full with tasks waiting on database, so earlier script execution task was waiting on free thread, next task was scheduled in the meantime, and then both were started in parallel, possibly in wrong order.<br />
I will think about it, but probably we have to serialize executions of alarm state change hooks.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/32524</link><guid isPermaLink="true">https://forum.netxms.org/post/32524</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Tue, 13 Jun 2023 15:58:54 GMT</pubDate></item><item><title><![CDATA[Reply to Possible Bug with HOOK:AlarmStateChange on Alarm Creation on Mon, 05 Jun 2023 13:34:56 GMT]]></title><description><![CDATA[<p dir="auto">Sorry for the delay! I've been in the hospital, but I'm all better now. </p>
<p dir="auto">We restarted the server shortly after this happened but only because it stopped returning the correct parameters to grafana SQL calls and we realized the disk space was low.</p>
]]></description><link>https://forum.netxms.org/post/32498</link><guid isPermaLink="true">https://forum.netxms.org/post/32498</guid><dc:creator><![CDATA[graeChris]]></dc:creator><pubDate>Mon, 05 Jun 2023 13:34:56 GMT</pubDate></item><item><title><![CDATA[Reply to Possible Bug with HOOK:AlarmStateChange on Alarm Creation on Mon, 29 May 2023 11:41:52 GMT]]></title><description><![CDATA[<p dir="auto">Copy constructor is not a problem in executing AlarmStateChange hook - script is executed from Alarm::executeHookScript, which in turn only called after m_state for source alarm was changed.<br />
I currently cannot see how hook could have been called with state 3 for new alarm. In described sequence of events, when did you restart the server?</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/32482</link><guid isPermaLink="true">https://forum.netxms.org/post/32482</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Mon, 29 May 2023 11:41:52 GMT</pubDate></item><item><title><![CDATA[Reply to Possible Bug with HOOK:AlarmStateChange on Alarm Creation on Thu, 25 May 2023 12:43:41 GMT]]></title><description><![CDATA[<p dir="auto">I haven't been able to duplicate this issue, but I think I discovered what caused the problem. Our server needed to be restarted as it was utilizing too much of the allocated resources. I believe this was causing the unexpected behavior as the database was also not updating values that were set for the object_properties.name field.<br />
For the sequence of events. </p>
<p dir="auto">1.) Agent Disabled on endpoint for alarm creation -&gt; Alarm created via EPP {status=0}<br />
      1.1) Alert is created in OpsGenie<br />
2.) Alarm marked as acknowledged by user -&gt; HOOK:AlarmStateChange is executed -Confirmed via trace()- {status=1}<br />
      2.1) Event is processed and opsgenie alert is acknowledged via cUrl<br />
3.) Alarm Enabled on endpoint -&gt; Alarm terminated via EPP  -&gt; HOOK:AlarmStateChange is executed -Confirmed via trace()- {status=3}<br />
      3.1) Alert is closed in OpsGenie<br />
4.) Agent Disabled on endpoint again for alarm creation -&gt; Alarm created via EPP {status=0} -&gt; Log shows that HOOK:AlarmStateChange has executed via trace and Alarm has {status=3}<br />
      4.1) Alert is created in Opsgenie via cUrl<br />
      4.2) Alert is marked as closed in opsgenie via cUrl</p>
<p dir="auto">I think this is more of a server related problem as we were running low on disk space at the time.</p>
]]></description><link>https://forum.netxms.org/post/32475</link><guid isPermaLink="true">https://forum.netxms.org/post/32475</guid><dc:creator><![CDATA[graeChris]]></dc:creator><pubDate>Thu, 25 May 2023 12:43:41 GMT</pubDate></item><item><title><![CDATA[Reply to Possible Bug with HOOK:AlarmStateChange on Alarm Creation on Tue, 02 May 2023 16:57:39 GMT]]></title><description><![CDATA[<p dir="auto">I've played a bit trying to replicate this, but did not get any success.</p>
<p dir="auto">There are two different things - creation of alarm and increasing count for already existing alarm.</p>
<p dir="auto">When a new alarm is created, <em>HOOK:AlarmStateChange</em> is not being executed (as it runs only when status changes for already existing alarm).</p>
<p dir="auto">But when alarm already exists and status changes (e.g. Alarm was previously acknowledged and changes to outstanding), this script will be executed.<br />
If alarm is terminated by EPP, script will also be executed and $alarm-&gt;state will be equal to 3.</p>
<p dir="auto">Can you give some exact sequence of what was happening on your system - was alarm already present on a node or it was created? Based on what event alarm is created? Are there any EPP rules that could modify or terminate the alarm?</p>
]]></description><link>https://forum.netxms.org/post/32425</link><guid isPermaLink="true">https://forum.netxms.org/post/32425</guid><dc:creator><![CDATA[Filipp Sudanov]]></dc:creator><pubDate>Tue, 02 May 2023 16:57:39 GMT</pubDate></item></channel></rss>