stitrace / zabbix_cisco_ise

Cisco ISE sessions zabbix monitoring template
0 stars 1 forks source link

Syntax error in Zabbix 6.0 #4

Open satheshr90 opened 4 months ago

satheshr90 commented 4 months ago

Hi, I imported the template in Zabbix 6.0 and made necessary changes in macros. But while testing item, it throws below error.

syntax error: line 1, column 0.

When i runt the ise.py script manually from zabbix server, it just provide ZBX_NOTSUPPORTED output.

Am i missing anything here?

Regards, Sathesh

stitrace commented 4 months ago

Hi, for local run ise.py you must set arguments, for example:

python ise.py 1.2.3.4 john PaSSword active`

Where 1.2.3.4 - ip address of Cisco ISE instance john/PaSSword - its credentials for access in Cisco ISE

About syntax error, template creates and tested on <=5.0 Zabbix version, may be it happens because it not compatible with new versions of Zabbix, need invistigation, but i dont have instances of that versions of Zabbix now and can't test it for fix. Sorry.

satheshr90 commented 4 months ago

Hi,

Thanks for your response. when i run locally like above, it just returns ZBX_NOTSUPPORTED output.

Thanks, Sathesh

stitrace commented 4 months ago

Hi,

try to make it executable chmod 711 ise.py and try to run it without python as first command, like this: chmod 711 ise.py ./ise.py 1.2.3.4 john PaSSword active

satheshr90 commented 4 months ago

Hi, Still the same.

stitrace commented 4 months ago

Hi, ok. I make fix commit to prevent this behavior https://github.com/stitrace/zabbix_cisco_ise/commit/6c541bac8752396a2bd32bcfcdc578b4b44d8446

stitrace commented 4 months ago

This commit will be right https://github.com/stitrace/zabbix_cisco_ise/commit/df0e46c1d8d1dc64ccb0f77794c6961393849129

stitrace commented 4 months ago

And you don't need to run this script under sudo

satheshr90 commented 4 months ago

Hi, Unfortunately i still receive the same error.

stitrace commented 4 months ago

output Show me output of this

satheshr90 commented 4 months ago

I am using python2. here is the o/p.

[root@hostnameexternalscripts]# python2 ise2.py 1.2.3.4 userid password ZBX_NOTSUPPORTED

stitrace commented 4 months ago

Hi, i see you forget add command at the last argument (active, test, etc..)

satheshr90 commented 4 months ago

I tried both ways.

[zabbixadm@hostnameexternalscripts]$ sudo python2 ise2.py 1.2.3.4 userid password active syntax error: line 1, column 0

[zabbixadm@hostnameexternalscripts]$ sudo ./ise2.py 1.2.3.4 userid password active syntax error: line 1, column 0

For both method, i receive same error now. syntax error: line 1, column 0

stitrace commented 4 months ago

Strange behavior. Let's try with this fix https://github.com/stitrace/zabbix_cisco_ise/commit/c863219f83de94dc83481277c890dbc2ffa3af40

satheshr90 commented 4 months ago

Exactly same error again. :(

stitrace commented 4 months ago

So, can you check what inside script? How you dowload it from github? cat ise2.py please.

satheshr90 commented 4 months ago

!/usr/bin/env python

import sys import requests import json import xmltodict import datetime

from requests.packages.urllib3.exceptions import InsecureRequestWarning # @UnresolvedImport requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # @UndefinedVariable

def get_item(url): try: user = sys.argv[2] passw = sys.argv[3] ise_request = requests.session() ise_request.auth = (user, passw) ise_request.verify = False ise_request.headers.update({'Connection': 'keep_alive'}) ise_response = ise_request.get(url) response = json.loads(json.dumps(xmltodict.parse(ise_response.text))) except Exception as exc: print(exc) exit(1) return response

def get_count(node_url): try: gc_resp = get_item(node_url + 'Session/ActiveCount') return (int(gc_resp['sessionCount']['count'])) except Exception as exc: print(exc) exit(1)

def get_active(node_url): try: today = datetime.datetime.today() - datetime.timedelta(hours=0, minutes=30) today = today.strftime("%Y-%m-%d %H:%M:%S") gc_resp = get_item(node_url + 'Session/AuthList/{0}/null'.format(today)) return (int(gc_resp['activeList']['@noOfActiveSession'])) except Exception as exc: print(exc) exit(1)

if not len(sys.argv) >= 5: print('ZBX_NOTSUPPORTED') exit(1) host = sys.argv[1] comm = sys.argv[4] ise_url = 'https://{0}/admin/API/mnt/'.format(host) if comm == 'count': print(get_count(ise_url)) elif comm == 'active': print(get_active(ise_url)) elif comm == 'test': print(host) print(ise_url) print("count") print(get_count(ise_url)) print("active") print(get_active(ise_url))