[ZBX-22327] AWS by HTTP is not working with Zabbix 6.0.13 Created: 2023 Feb 08  Updated: 2023 Oct 05  Resolved: 2023 Oct 05

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 6.0.13
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Fabrizio Regalli Assignee: Alexander Bakaldin
Resolution: Duplicate Votes: 9
Labels: templates
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screenshot from 2023-02-08 18-47-35.png     PNG File image-2023-02-09-10-36-05-391.png     PNG File image-2023-04-14-09-20-10-972.png     PNG File image-2023-05-24-14-52-31-368.png     PNG File image-2023-05-24-15-02-31-272.png    
Issue Links:
Sub-task
part of ZBXNEXT-8283 Implement role based authentication f... Closed
Sprint: Sprint 100 (May 2023), Sprint 101 (Jun 2023), Sprint 102 (Jul 2023), Sprint 103 (Aug 2023), Sprint 104 (Sep 2023), Sprint 105 (Oct 2023)

 Description   

Steps to reproduce:

  1. Get the 4 templates from zabbix git
  2. Import in zabbix
  3. Create one item in order to discovery AWS services
  4. Wait a bit and check the result of EC2 instance discovery

 

It surely brake something here: 

        instance.forEach(function (item, index, instance_array) {
                        if (typeof item !== 'object'
                            || typeof item.instancesSet !== 'object'
                            || typeof item.instancesSet.item !== 'object'
                            || item.instancesSet.item.hasOwnProperty('instanceId') === false)
                            throw 'Failed response parse. Check debug log for more information.';
 

The data from AWS seems to be right.

Someone here https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/452053-error-failed-response-parse-check-debug-log-for-more-information-in-aws-by-http is suggesting to change

                setParams: function (params) {
                    ['access_key', 'region', 'secret_key'].forEach(function (field) {
                        if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') {
                            throw 'Required param is not set: "' + field + '".';
                        }

to
setParams: function (params) {
AwsEC2.params = params;
},​
 

But at least for me this solution does not work.

Thank you!

 



 Comments   
Comment by Alexander Bakaldin [ 2023 Feb 09 ]

I was unable to reproduce the issue in 6.0.13.
Can you show the logs and the test result in the web interface (displaying the "Test" button in the discovery rule settings)?
Please hide your credentials.

Comment by Fabrizio Regalli [ 2023 Feb 09 ]

Hi!

038408:20230208:104405.869 [ AWS EC2 ] Sending request: https://ec2.eu-central-1.amazonaws.com/?Action=DescribeInstances&Version=2016-11-15

 

4038408:20230208:104406.263 [ AWS EC2 ] Received response with status code 200: <?xml version="1.0" encoding="UTF-8"?>
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
    <requestId>xxxxxx-1111-2222-3333-153ad10d01a9</requestId>
    <reservationSet>
        <item>
            <reservationId>r-xxxx</reservationId>
            <ownerId>11111111111</ownerId>
            <groupSet/>
            <instancesSet>
                <item>
                    <instanceId>i-xxxx</instanceId>
                    <imageId>ami-xxx</imageId>
                    <instanceState>
                        <code>80</code>
                        <name>stopped</name>
                    </instanceState>
                    <privateDnsName>ip-xxx.compute.internal</privateDnsName>
                    <dnsName/>
                    <reason>User initiated (2022-04-12 05:40:56 GMT)</reason>
                    <keyName>aaaa</keyName>
                    <amiLaunchIndex>0</amiLaunchIndex>
                    <productCodes/>
                    <instanceType>t4g.medium</instanceType>
                    <launchTime>2022-04-12T05:18:11.000Z</launchTime>
                    <placement>

This list is very long, more then 70 instances.

However the result from AWS seems to be right. I've extracted that part and all tags are correctly filled into.

4038408:20230208:104406.397 [ AWS EC2 ] ERROR: Failed response parse. Check debug log for more information.
4038408:20230208:104406.397 zbx_es_execute() output:'{"error":"Failed response parse. Check debug log for more information."}'

Here's the screenshot from the GUI:

 

 

Thank you!

Comment by Fabrizio Regalli [ 2023 Feb 09 ]

I noticed the XML that comes from AWS is grouped by reservationId but unfortunately this field could be related to more instances.

From the AWS documentation:

The ID of the instance’s reservation. A reservation ID is created any time you launch an instance. A reservation ID has a one-to-one relationship with an instance launch request, but can be associated with more than one instance if you launch multiple instances using the same launch request. For example, if you launch one instance, you get one reservation ID. If you launch ten instances using the same launch request, you also get one reservation ID.

Tested with jq (c file contains the whole list of ec2 instances)

Working situation

jq -r .DescribeInstancesResponse.reservationSet.item[60].instancesSet.item.instanceId < c
i-0dca96461027d5916

Not working situation

jq -r .DescribeInstancesResponse.reservationSet.item[61].instancesSet.item[].instanceId < c
i-0a4fd1354b8284950
i-09998a2cece633das

That means for the instance 61 there is one reservationID associated with 2 instances and this cause the issue.

A possible workaround could be remove this control from the Javascript

item.instancesSet.item.hasOwnProperty(‘instanceId’) === false

but without it, we can introduce others possible issue.

I'm not a Javascript expert but maybe with some lines of code is possible to prevent this situation. On the other hand, AWS API should taking care of this situation and return a single value and not an array, for instance.

Seems it's not possible to change the reservationid in some way on AWS.

Tested in another environment (different region) with less instances without same reservationID associated to multiple instances and the script works fine.

Thanks!

Comment by Alexander Bakaldin [ 2023 Feb 12 ]

Thanks for the feedback.
Message: "Failed response parse. Check debug log for more information." can only be in one case:

            if (typeof item !== 'object'
                || typeof item.instancesSet !== 'object'
                || typeof item.instancesSet.item !== 'object'
                || item.instancesSet.item.hasOwnProperty('instanceId') === false)
                throw 'Failed response parse. Check debug log for more information.';

This condition simply checks the structure and the existence of "instancesSet.item.instanceId" fields. For some reason, some instance has a different structure. It may require a special handler.
Can you change the line:

throw 'Failed response parse. Check debug log for more information.';

on the:

throw 'Failed response parse. Check debug log for more information. DEBUG: ' + JSON.stringify(item);

?

This will help to get a more detailed message in the log file.

Comment by Fabrizio Regalli [ 2023 Apr 14 ]

Hi again Alexander,

sorry for taking so long in replying.

I can confirm what I wrote previously - the issue is related to the reservation-id: this is what happens in the console if I filter for that reservation-id If the script found more than 1 instance with the same reservation-id it fails.

The DEBUG log does not help so much: I'm able to see all the attributes of the instances and they are all "jsonified" correctly until the script encounter the instance with the duplicated reservation-id. 

In support of my theory I tried to delete one of the instance with the same reservation-id and the script works fine.

What I would like to ask you, if it's possible to add an exception to your code in order to managing case like mine (mainly cause by autoscaling)

Thank you.

  

Comment by Alexander Bakaldin [ 2023 Apr 17 ]

Thank you very much for your comments!
Yes, we managed to reproduce the problem. In the near future, I will update the script.

Comment by Nina Dutra [ 2023 May 24 ]

In my environment I just removed lines 102 to 106 from the discovery rule script and it worked to collect the information.

Comment by Alexander Bakaldin [ 2023 Oct 03 ]

It was resolved during ZBXNEXT-8283.

Generated at Thu Mar 27 03:15:35 EET 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.