haproxy.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:plugins 作者: site24x7 项目源码 文件源码
def _openURL3(self):
        try:
            if (self._userName and self._userPass):
                password_mgr = urlconnection.HTTPPasswordMgr()
                password_mgr.add_password(self._realm, self._url, self._userName, self._userPass)
                auth_handler = urlconnection.HTTPBasicAuthHandler(password_mgr)
                opener = urlconnection.build_opener(auth_handler)
                urlconnection.install_opener(opener)
            response = urlconnection.urlopen(self._url, timeout=10)
            if (response.status == 200):
                byte_responseData = response.read()
                str_responseData = byte_responseData.decode('UTF-8')
                self._parseStats(str_responseData)
            else:
                #self.dictInterfaceData['status'] = 0
                self.dictInterfaceData['msg'] = 'Response status code from haproxy url is :'  + str(response.status)
        except HTTPError as e:
            #self.dictInterfaceData['status'] = 0
            self.dictInterfaceData['msg'] ='Haproxy stats url has HTTP Error '+str(e.code)
        except URLError as e:
            #self.dictInterfaceData['status'] = 0
            self.dictInterfaceData['msg'] = 'Haproxy stats url has URL Error '+str(e.reason)
        except InvalidURL as e:
            #self.dictInterfaceData['status'] = 0
            self.dictInterfaceData['msg'] = 'Haproxy stats url is invalid URL'
        except Exception as e:
            #self.dictInterfaceData['status'] = 0
            self.dictInterfaceData['msg'] = 'Haproxy stats URL error : ' + str(e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号