Exemplo n.º 1
0
 def __createWmHost(self):
     group_id = 0
     group = self.zapi.hostgroup.get(filter={"name": self.zbx_wmgroup})
     try:
         group_id = group[0]['groupid']
     except:
         sendToLogger('debug', 'Web Monitor group \"' + self.zbx_wmgroup + '\" creation started.')
         group = self.zapi.hostgroup.create({"name": self.zbx_wmgroup})
         sendToLogger('debug', 'Web Monitor group created with group id = ' + group['groupids'][0])
         group_id = group['groupids'][0]
     if (group_id):
         try:
             sendToLogger('debug', 'Web Monitor host \"' + self.zbx_wmhostname + '\" creation started.')
             self.zapi.host.create({"host": self.zbx_wmhostname,
                                    "groups": [
                                        {
                                            "groupid": group_id
                                        }
                                     ],
                                    "interfaces": [
                                        {
                                            "type": "1",
                                            "main": "1",
                                            "useip": "1",
                                            "ip": "127.0.0.1",
                                            "dns": "",
                                            "port": "10050"
                                        }
                                    ]
                                    })
             sendToLogger('debug', 'Web Monitor host \"' + self.zbx_wmhostname + '\" creation successful.')
         except:
             sendToLogger('error', 'Web Monitor host \"' + self.zbx_wmhostname + '\" creation failed.')
Exemplo n.º 2
0
 def __checkSiteStatus(self, request_status, allowable_status):
     if (request_status == allowable_status):
         return True
     else:
         sendToLogger(
             'warn',
             'HTTP status ' + str(request_status) + ' not allowable.')
         return False
Exemplo n.º 3
0
 def getDomainsList(self):
     try:
         conf = self.__readConfFile()
     except:
         sendToLogger(
             'error',
             'Config file not found on ' + str(self.nginx_confpath))
     domain_list = self.__parseDomains(conf)
     return domain_list
Exemplo n.º 4
0
 def __getSite(self, domain, protocol):
     url = protocol + '://' + domain
     try:
         http = urllib3.PoolManager()
         request = http.request('GET', url)
         return request
     except urllib3.exceptions.NewConnectionError:
         sendToLogger('error', 'Connection failed  for ' + str(domain))
         exit(2)
     except urllib3.exceptions.MaxRetryError:
         sendToLogger('error', 'Max retries exceeded for ' + str(domain))
         exit(2)
Exemplo n.º 5
0
 def doCheck(self):
     request = self.__getSite(self.site, self.site_protocol)
     if (self.__checkSiteStatus(request.status,
                                self.allowable_http_status)):
         sendToLogger('debug', 'Checking site data ' + str(self.site))
         if (self.__checkSiteData(request.data, self.site_keyword)):
             sendToLogger('ok',
                          'Site data checking ' + str(self.site) + ' OK')
             return True
         else:
             sendToLogger('warn',
                          'Site data checking ' + str(self.site) + ' FAIL')
             return False
     else:
         sendToLogger('warn',
                      'Site status checking ' + str(self.site) + ' FAIL')
         return False
Exemplo n.º 6
0
 def __createConnection(self):
     sendToLogger('debug', 'Connecting to zabbix-server on ' + str(self.zbx_url))
     try:
         zapi = ZabbixAPI(self.zbx_url)
         zapi.login(self.zbx_user, self.zbx_pass)
         sendToLogger('debug', 'Connected to zabbix-server API Version ' + zapi.api_version())
         return zapi
     except:
         sendToLogger('error', 'Connection to zabbix-server on ' + str(self.zbx_url) + ' failed.')
         exit(2)
Exemplo n.º 7
0
 def __checkWmHost(self):
     host = self.zapi.host.get(output=["status"], filter={"host": self.zbx_wmhostname}, limit=1)
     try:
         host_status = host[0]['status']
         self.wmhost_id = host[0]['hostid']
     except:
         sendToLogger('debug', 'Web Monitor host not created.')
         return False
     if (host_status == '1' or host_status == '0'):
         sendToLogger('debug', 'Web Monitor host \"' + self.zbx_wmhostname + '\" already created.')
         return True
     else:
         sendToLogger('debug', 'Web Monitor host not created.')
         return False
Exemplo n.º 8
0
 def __checkSiteData(self, request_data, keyword):
     if re.search(str(keyword), str(request_data.decode('utf-8'))):
         return True
     else:
         sendToLogger('warn', 'Keyword ' + str(keyword) + ' not found.')
         return False