qk4l / zabbix-cachet

Python script which sync Zabbix IT Services with Cachet
MIT License
80 stars 32 forks source link

TypeError: list indices must be integers, not str #30

Closed erdeerdeerde closed 6 years ago

erdeerdeerde commented 6 years ago

Hello,

I have a TypeError:

2018-01-11 15:32:19 CET DEBUG: (MainThread) Creating Component Group FOOBAR...
2018-01-11 15:32:19 CET DEBUG: (MainThread) Sending to http://cachet.local/api/v1/components/groups: {
    "collapsed": 2,
    "name": "FOOBAR"
}
2018-01-11 15:32:19 CET INFO: (MainThread) Starting new HTTP connection (1): cachet.local
2018-01-11 15:32:19 CET DEBUG: (MainThread) "POST /api/v1/components/groups HTTP/1.1" 301 185
2018-01-11 15:32:19 CET INFO: (MainThread) Starting new HTTPS connection (1): cachet.local
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:791: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
2018-01-11 15:32:19 CET DEBUG: (MainThread) "GET /api/v1/components/groups HTTP/1.1" 200 None
2018-01-11 15:32:19 CET DEBUG: (MainThread) Response Body: {
    "meta": {
        "pagination": {
            "count": 0,
            "links": {
                "next_page": null,
                "previous_page": null
            },
            "current_page": 1,
            "total_pages": 0,
            "per_page": 20,
            "total": 0
        }
    },
    "data": []
}
Traceback (most recent call last):
  File "zabbix-cachet.py", line 701, in <module>
    zbxtr2cachet_new = init_cachet(itservices)
  File "zabbix-cachet.py", line 604, in init_cachet
    group = cachet.new_components_gr(zbx_service['name'])
  File "zabbix-cachet.py", line 389, in new_components_gr
    logging.info('Component Group {} was created ({})'.format(params['name'], data['data']['id']))
TypeError: list indices must be integers, not str

I dont know why data is a list here, i am using the tools from the requierements.txt in the exact versions and Zabbix 3.4.4 as well as cachet: 2.4.0-dev

qk4l commented 6 years ago

Hi, could you please change cachet url to use https and disable https check (or add you CA to trust store)?

It will help to avoid 301 redirect. Seems request does not follow it.

Thanks.

On Thu, Jan 11, 2018, 6:14 PM Martin Weber notifications@github.com wrote:

Hello,

I have a TypeError:

2018-01-11 15:32:19 CET DEBUG: (MainThread) Creating Component Group FOOBAR... 2018-01-11 15:32:19 CET DEBUG: (MainThread) Sending to http://cachet.local/api/v1/components/groups: { "collapsed": 2, "name": "FOOBAR" } 2018-01-11 15:32:19 CET INFO: (MainThread) Starting new HTTP connection (1): cachet.local 2018-01-11 15:32:19 CET DEBUG: (MainThread) "POST /api/v1/components/groups HTTP/1.1" 301 185 2018-01-11 15:32:19 CET INFO: (MainThread) Starting new HTTPS connection (1): cachet.local /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:791: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning) 2018-01-11 15:32:19 CET DEBUG: (MainThread) "GET /api/v1/components/groups HTTP/1.1" 200 None 2018-01-11 15:32:19 CET DEBUG: (MainThread) Response Body: { "meta": { "pagination": { "count": 0, "links": { "next_page": null, "previous_page": null }, "current_page": 1, "total_pages": 0, "per_page": 20, "total": 0 } }, "data": [] } Traceback (most recent call last): File "zabbix-cachet.py", line 701, in zbxtr2cachet_new = init_cachet(itservices) File "zabbix-cachet.py", line 604, in init_cachet group = cachet.new_components_gr(zbx_service['name']) File "zabbix-cachet.py", line 389, in new_components_gr logging.info('Component Group {} was created ({})'.format(params['name'], data['data']['id'])) TypeError: list indices must be integers, not str

I dont know why data is a list here, i am using the tools from the requierements.txt in the exact versions and Zabbix 3.4.4 as well as cachet: 2.4.0-dev

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/qk4l/zabbix-cachet/issues/30, or mute the thread https://github.com/notifications/unsubscribe-auth/AIAVS4fq3GpWIQfFeAdU6FLeyry0fDYVks5tJiU2gaJpZM4Ra_rv .

-- Best regards, Artyom

erdeerdeerde commented 6 years ago

I did as you told me and now it returns the following error:


2018-01-11 17:12:38 CET DEBUG: (MainThread) "GET /api/v1/components HTTP/1.1" 200 None
2018-01-11 17:12:38 CET DEBUG: (MainThread) Response Body: {
    "meta": {
        "pagination": {
            "count": 2,
            "links": {
                "next_page": null,
                "previous_page": null
            },
            "current_page": 1,
            "total_pages": 1,
            "per_page": 20,
            "total": 2
        }
    },
    "data": [
        {
            "status": 1,
            "deleted_at": null,
            "description": "foo",
            "status_name": "Funktionsf\u00e4hig",
            "created_at": "2018-01-11 15:52:18",
            "tags": {
                "": ""
            },
            "enabled": true,
            "updated_at": "2018-01-11 15:52:18",
            "id": 5,
            "meta": null,
            "link": "bar",
            "group_id": 2,
            "order": 0,
            "name": "baz"
        },
        {
            "status": 1,
            "deleted_at": null,
            "description": "qux",
            "status_name": "Funktionsf\u00e4hig",
            "created_at": "2018-01-11 16:08:17",
            "tags": {
                "": ""
            },
            "enabled": true,
            "updated_at": "2018-01-11 16:08:17",
            "id": 6,
            "meta": null,
            "link": "",
            "group_id": 2,
            "order": 0,
            "name": "quo"
        }
    ]
}
2018-01-11 17:12:38 CET DEBUG: (MainThread) Creating Cachet component Customer Impact...
2018-01-11 17:12:38 CET DEBUG: (MainThread) Sending to https://cachet.local/api/v1/components: {
    "status": "1",
    "link": "",
    "name": "Customer Impact",
    "group_id": 3,
    "description": ""
}
2018-01-11 17:12:38 CET INFO: (MainThread) Starting new HTTPS connection (1): cachet.local
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:791: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
2018-01-11 17:12:38 CET DEBUG: (MainThread) "POST /api/v1/components HTTP/1.1" 400 None
2018-01-11 17:12:38 CET ERROR: (MainThread) ClientHttpError[https://cachet.local/api/v1/components, 400: {"errors":[{"id":"ec9b6e6c-b328-43fa-8585-c785150bf001","status":400,"title":"Bad Request","detail":"The request cannot be fulfilled due to bad syntax.","meta":{"details":["Das Format von description ist ung\u00fcltig."]}}]}]
2018-01-11 17:12:38 CET ERROR: (MainThread) 'NoneType' object has no attribute '__getitem__'

Best Regards,

Martin

qk4l commented 6 years ago

Oh, I missed that you use Cachet 2.4. It's a known bug #24

On Thu, Jan 11, 2018, 7:21 PM Martin Weber notifications@github.com wrote:

I did as you told me and now it returns the following error:

2018-01-11 17:12:38 CET DEBUG: (MainThread) "GET /api/v1/components HTTP/1.1" 200 None 2018-01-11 17:12:38 CET DEBUG: (MainThread) Response Body: { "meta": { "pagination": { "count": 2, "links": { "next_page": null, "previous_page": null }, "current_page": 1, "total_pages": 1, "per_page": 20, "total": 2 } }, "data": [ { "status": 1, "deleted_at": null, "description": "foo", "status_name": "Funktionsf\u00e4hig", "created_at": "2018-01-11 15:52:18", "tags": { "": "" }, "enabled": true, "updated_at": "2018-01-11 15:52:18", "id": 5, "meta": null, "link": "bar", "group_id": 2, "order": 0, "name": "baz" }, { "status": 1, "deleted_at": null, "description": "qux", "status_name": "Funktionsf\u00e4hig", "created_at": "2018-01-11 16:08:17", "tags": { "": "" }, "enabled": true, "updated_at": "2018-01-11 16:08:17", "id": 6, "meta": null, "link": "", "group_id": 2, "order": 0, "name": "quo" } ] } 2018-01-11 17:12:38 CET DEBUG: (MainThread) Creating Cachet component Customer Impact... 2018-01-11 17:12:38 CET DEBUG: (MainThread) Sending to https://cachet.local/api/v1/components: { "status": "1", "link": "", "name": "Customer Impact", "group_id": 3, "description": "" } 2018-01-11 17:12:38 CET INFO: (MainThread) Starting new HTTPS connection (1): cachet.local /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:791: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning) 2018-01-11 17:12:38 CET DEBUG: (MainThread) "POST /api/v1/components HTTP/1.1" 400 None 2018-01-11 17:12:38 CET ERROR: (MainThread) ClientHttpError[https://cachet.local/api/v1/components, 400: {"errors":[{"id":"ec9b6e6c-b328-43fa-8585-c785150bf001","status":400,"title":"Bad Request","detail":"The request cannot be fulfilled due to bad syntax.","meta":{"details":["Das Format von description ist ung\u00fcltig."]}}]}] 2018-01-11 17:12:38 CET ERROR: (MainThread) 'NoneType' object has no attribute 'getitem'

Best Regards,

Martin

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/qk4l/zabbix-cachet/issues/30#issuecomment-356979780, or mute the thread https://github.com/notifications/unsubscribe-auth/AIAVS9HZpCONyAk-_3rMGjskcTg69ZL2ks5tJjUfgaJpZM4Ra_rv .

-- Best regards, Artyom