ginoledesma / sunpower-pvs-exporter

A Prometheus Exporter for the SunPower PVS monitoring system
MIT License
77 stars 24 forks source link

sunpowerconsole.com timing out #13

Open kskenyon opened 2 years ago

kskenyon commented 2 years ago

I can access the console using 172.27.153.1 so I know it's working. I tried hard coding that into exporter.py but it won't take for some reason. I did setup.py build and setup.py install but sunpowerconsole.com still keeps coming up in a journalctl error as below.

Is the Sunpower PSV5 dhcp server sending a bad hostname somehow? The hardcoded address comes up in the sunpower-pvs-exporter .egg file in dist-packages. Stumped.

requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='sunpowerconsole.com', port=80): Max retries exceeded with url: /cgi-bin/dl_cgi?Command=Start (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x757aba50>, 'Connection to sunpowerconsole.com timed out. (connect timeout=30)'))

curl http://sunpower.console.com/cgi-bin/dl_cgi?Command=Start <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

404 Not Found

Not Found

The requested URL /cgi-bin/dl_cgi was not found on this server.

curl http://172.27.153.1/cgi-bin/dl_cgi?Command=Start { "result": "succeed", "supervisor": { "SWVER": "2022.3, Build 5206", "SERIAL": "ZT182985000441D1548", "MODEL": "PVS5", "FWVER": "0.0.0" } }

dacarson commented 1 year ago

I too am running into this issue. I thought it might be because of the multihome raspberry pi that I am running it on, and the dns lookup was going the default route (I don't think sunpowerconsole.com is resolvable over the internet), so I used the parameter --hostname and passed in 172.27.153.1, and I still get the same issue. Like @kskenyon the commands all work fine using curl.

dacarson commented 1 year ago

I found there is a way to force the python app to connect to the right interface, following information I found here: https://stackoverflow.com/questions/28773033/python-requests-how-to-bind-to-different-source-ip-for-each-request In exporter.py I added two lines as shown below. Note, however, the IP address needs to match the IP address that it received from the PVS unit. It could change, so, this patch is a hack to get it working.


    def __init__(self,
                 # hostname="sunpowerconsole.com",
                 hostname="172.27.153.1",
                 port=80,
                 scheme="http",
                 timeout=(5, 5),
                 use_device_data_timestamp=False,
                ):
        self.session = requests.Session()

        # The following two lines force the URL binding to happen on the PVS interface
        new_source = source.SourceAddressAdapter("172.27.153.156")
        self.session.mount('http://', new_source)

        self.use_device_data_timestamp = use_device_data_timestamp

        self.timeout = timeout
        self.url = "{scheme}://{hostname}:{port}/cgi-bin/dl_cgi".format(
            scheme=scheme,
            hostname=hostname,
            port=port
        )
dacarson commented 11 months ago

If you make the change I suggested above, make sure that you first install the python library pip install requests_toolbelt and also add at the top of the exporter.py file: from requests_toolbelt.adapters import source otherwise it will fail to run because 'source' is not defined.