adriaaah / monit-dashboard

A web dashboard for rule all monit servers at a glance
GNU Affero General Public License v3.0
26 stars 8 forks source link

ValueError: Expecting property name: line 2 column 3 (char 4) #3

Closed s-m-i-c-h-a closed 7 years ago

s-m-i-c-h-a commented 7 years ago

Hi,

On my system it does not work. I get the following error:

http://0.0.0.0:8888/ Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/web/application.py", line 239, in process return self.handle() File "/usr/lib/python2.7/dist-packages/web/application.py", line 230, in handle return self._delegate(fn, self.fvars, args) File "/usr/lib/python2.7/dist-packages/web/application.py", line 420, in _delegate return handle_class(cls) File "/usr/lib/python2.7/dist-packages/web/application.py", line 396, in handle_class return tocall(*args) File "./bin/monit-dashboard.py", line 72, in GET return render.index(output=getMonit(), now=datetime.datetime.now()) File "./bin/monit-dashboard.py", line 34, in getMonit cf = json.loads(f.read()) File "/usr/lib/python2.7/json/init.py", line 338, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 2 column 3 (char 4)

127.0.0.1:37400 - - [28/Feb/2017 10:23:51] "HTTP/1.1 GET /" - 500 Internal Server Error

I have the following system: cat /etc/debian_version 8.7 uname -a Linux gatekeeper 3.4.106-cubieboard #2 SMP PREEMPT Tue Feb 17 06:16:56 CET 2015 armv7l GNU/Linux

dpkg -l python-xmltodict python-requests python-webpy Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=============================-===================-===================-=============================================================== ii python-requests 2.4.3-6 all elegant and simple HTTP library for Python2, built for human be ii python-webpy 1:0.37+20120626-1 all Web framework for Python applications ii python-xmltodict 0.9.0-1 all Makes working with XML feel like you are working with JSON

Many thanks Michael

adriaaah commented 7 years ago

Hi Michael,

how do you run it? Is it able to open the network connection? How did you change the port? I didn't test it under ARM architecture but I think it shouldn't be a problem.

Waiting for your feedback.

s-m-i-c-h-a commented 7 years ago

Hi,

thanks for the fast answer. I have run it as user "root" on my cubietruck (ARM), but I have also tried on a Intel box with no luck. Both are runnign Debian Jessie

root@gatekeeper:~/monit-dashboard/monit-dashboard-master# ./bin/monit-dashboard.py http://0.0.0.0:8888/

As you the Listen is running. root@gatekeeper:~/monit-dashboard/monit-dashboard-master# netstat -atunp | grep 8888 tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 30866/python

The "/help" is working. 127.0.0.1:42171 - - [28/Feb/2017 15:47:38] "HTTP/1.1 GET /help" - 200 OK 127.0.0.1:42173 - - [28/Feb/2017 15:47:39] "HTTP/1.1 GET /favicon.ico" - 404 Not Found

But, when I call "/" I get the following error message Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/web/application.py", line 239, in process return self.handle() File "/usr/lib/python2.7/dist-packages/web/application.py", line 230, in handle return self._delegate(fn, self.fvars, args) File "/usr/lib/python2.7/dist-packages/web/application.py", line 420, in _delegate return handle_class(cls) File "/usr/lib/python2.7/dist-packages/web/application.py", line 396, in handle_class return tocall(*args) File "./bin/monit-dashboard.py", line 72, in GET return render.index(output=getMonit(), now=datetime.datetime.now()) File "./bin/monit-dashboard.py", line 34, in getMonit cf = json.loads(f.read()) File "/usr/lib/python2.7/json/init.py", line 338, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 2 column 3 (char 4)

127.0.0.1:42188 - - [28/Feb/2017 15:48:45] "HTTP/1.1 GET /" - 500 Internal Server Error

and in the browser I get "internal server error"

Do you have an idea?

Many Thanks Michael

s-m-i-c-h-a commented 7 years ago

I change the port in "bin/monit-dashboard.py"

if name == "main": app = monitDashboard(urls, globals()) app.run(port=8888)

The last line from 8080 to 8888, because I have already running something on TCP/8080

many Thanks

s-m-i-c-h-a commented 7 years ago

Some hint, the Script as you refer on your github page "https://imil.net/blog/2016/03/16/Fetch-monit-status-in-JSON/" is working fine

s-m-i-c-h-a commented 7 years ago

I did run a tcpdump and I do not see any communication to my monit service on TCP/2812.

Thank you very much for your help!!!

Michael

adriaaah commented 7 years ago

Hi Michael, thanks for your feedback. Usually, during the tests I ran, it returned a 500 when was unable to connect to a monit instsance, but I would gather some more data from your environment.

Glad you could fix it and hope it is useful to you.

s-m-i-c-h-a commented 7 years ago

Hi,

sorry, but I did not fix it. it does not working.

Sorry that was a miss-understanding. I get still the errors and it does not work

Can you please help me?

Thanks Michael

adriaaah commented 7 years ago

Sorry for the misunderstanding; I reopened it. So, do you have your Monit instance up and running? Could be there any network issue (like firewall)? You will see traffic as soon as you refresh the page (the 5 minutes refresh works if the page was loaded successfully).

BTW, which Python version are you using?

Edit: Could you please provide the config.json file (but masking sensitive data)?

adriaaah commented 7 years ago

I tried to reproduce the issue, but I couldn't. Below you will find the steps I did. All of them are performed in a Vagrant instance created from scratch (vagrant init debian/jessie64). Please see the Gist listed at the bottom for further details about my Vagrantfile.

Then, inside the VM (vagrant ssh):

As root (sudo su):

apt install python-webpy && apt install python-xmltodict python-requests
apt install git
apt install monit

As vagrant user:

git clone https://github.com/adriaaah/monit-dashboard.git
cd monit-dashboard/

I replaced the string 8080 with 8888 in the bin/monit-dashboard.py file (line 83)

./bin/monit-dashboard.py

As root again, I edited /etc/monit/monitrc and restarted the service (service monit restart). You will find monitrc in the gist listed at the bottom.

As vagrant user I updated server.json file (please you will find it in the Gist listed at the bottom).

Finally, I pointed my browser to http://localhost:8888 and the app did its job.

The output was:

./bin/monit-dashboard.py 
http://0.0.0.0:8888/
2017-02-28 20:24:40.680431
10.0.2.2:59562 - - [28/Feb/2017 20:24:40] "HTTP/1.1 GET /" - 200 OK
10.0.2.2:59563 - - [28/Feb/2017 20:24:40] "HTTP/1.1 GET /static/monit-dashboard.js" - 200 
10.0.2.2:59562 - - [28/Feb/2017 20:24:40] "HTTP/1.1 GET /static/monit-dashboard.css" - 200 
10.0.2.2:59562 - - [28/Feb/2017 20:24:41] "HTTP/1.1 GET /static/img/error.png" - 200 10.0.2.2:59563 - - [28/Feb/2017 20:24:41] "HTTP/1.1 GET /static/img/ok.png" - 200 

10.0.2.2:59562 - - [28/Feb/2017 20:24:41] "HTTP/1.1 GET /favicon.ico" - 404 Not Found
10.0.2.2:59562 - - [28/Feb/2017 20:24:41] "HTTP/1.1 GET /favicon.ico" - 404 Not Found

The gist: https://gist.github.com/adriaaah/779ef319a49683315f72fcc182689a22

I even tried with the most up to date packages (apt update && apt upgrade) and even running the app as root: it worked to me in all the cases.

s-m-i-c-h-a commented 7 years ago

Hi,

thank you very much for your super support!!!! Ok, now I found the problem.

In your example config file "servers.json.example" there is a typo included. In Line 2 there is missing a "

Line is: Server A": {

but must be "Server A": {

After added the " it works.

Sometimes it's good to enable syntax highlighting in vim :-)

WOW, your Python-Script looks very good, and do exactly what I need.

Many, many thanks!!

Best regards Michael

adriaaah commented 7 years ago

Fixed with https://github.com/adriaaah/monit-dashboard/pull/4. Thanks for your input.