Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k8s-stats.py returning index problem #12

Open
blondviper opened this issue Jul 7, 2021 · 2 comments
Open

k8s-stats.py returning index problem #12

blondviper opened this issue Jul 7, 2021 · 2 comments

Comments

@blondviper
Copy link

blondviper commented Jul 7, 2021

Running k8s-stats.py from terminal says:
Traceback (most recent call last): File "./k8s-stats.py", line 20, in <module> target = 'pods' if 'containers' == sys.argv[2] else sys.argv[2] IndexError: list index out of range

I would appreciate any help. Thanks.

@blondviper blondviper changed the title implementation place k8s-stats.py returning index problem Jul 8, 2021
@rhaamo
Copy link

rhaamo commented Aug 15, 2021

This is expected, you shouldn't launch the script without args, you can test it working by doing:

root@aubergine:~# /etc/zabbix/scripts/k8s-stats.py discovery pods
{"data": [{"{#NAMESPACE}": "kube-system", "{#NAME}": "metrics-server-86cbb8457f-2ltz6"}, {"{#NAMESPACE}": "kube-system", "{#NAME}": "local-path-provisioner-5ff76fc89d-b5wvt"}, {"{#NAMESPACE}": "kube-system", "{#NAME}": "coredns-7448499f4d-mdgkx"}, {"{#NAMESPACE}": "traefik", "{#NAME}": "svclb-traefik-n59td"}, {"{#NAMESPACE}": "kubernetes-dashboard", "{#NAME}": "dashboard-metrics-scraper-856586f554-bp66h"}, {"{#NAMESPACE}": "kubernetes-dashboard", "{#NAME}": "kubernetes-dashboard-67484c44f6-bvl8k"}, {"{#NAMESPACE}": "default", "{#NAME}": "awx-operator-545497f7d5-g2jqr"}, {"{#NAMESPACE}": "awx", "{#NAME}": "awx-85446fc8f4-9rtsf"}, {"{#NAMESPACE}": "kresus", "{#NAME}": "kresus-84bb497584-dwc2d"}, {"{#NAMESPACE}": "traefik", "{#NAME}": "traefik-dfddb74d5-rph4g"}]}
root@aubergine:~# /etc/zabbix/scripts/k8s-stats.py discovery nodes
{"data": [{"{#NAME}": "aubergine"}]}

Instead of pods or nodes you can see the list in script:

targets = ['pods','nodes','containers','deployments','apiservices','componentstatuses']

@HeineNK
Copy link

HeineNK commented Nov 10, 2021

Ill have to admit, I am so much a noob here. :) But I am not getting any info at all in zabbix, and if I try to use the script from cli I get the following error. :

/usr/lib/zabbix/externalscripts# ./k8s-stats.py discovery pods
Traceback (most recent call last):
File "./k8s-stats.py", line 65, in
data = json.loads(rawdata())
File "./k8s-stats.py", line 46, in rawdata
rawdata = urllib2.urlopen(req, context=ctx).read()
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 435, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 473, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants