def install(self): if not check_root(): print("Please run the program using sudo privileges") raise PermissionDeniedException( "Permission Denied. Run with admin rights.") self.setup_logstash()
def pull_image(self): if not check_root(): print("Please run the program using sudo privileges") raise PermissionDeniedException("Permission Denied. Run with admin rights.") try: self.client.images.pull(self.config[self.KIBANA_SECTION][self.KIBANA_IMAGE]) except docker.errors.APIError as err: print("The server returns an error. \n{}".format(str(err))) raise err
def pull_image(self): if not check_root(): self.logger.error("Please run the program using sudo privileges") raise PermissionDeniedException( "Permission Denied. Run with admin rights.") try: self.client.images.pull( self.config[self.LDAP_SECTION][self.LDAP_IMAGE]) self.logger.info("Successfully pulled LDAP docker image.") except docker.errors.APIError as err: self.logger.error("The server returns an error. \n{}".format( str(err))) raise err
def setup_logstash(self): if not check_root(): print("Please run the program using sudo privileges") raise PermissionDeniedException( "Permission Denied. Run with admin rights.") if not os.path.exists( self.config[self.LOGSTASH_SECTION][self.LOGSTASH_CONF]): print( "Unable to find the logstash config folder at mentioned path") raise FileNotFoundError try: self.pull_image() self.update_logstash_config() self.client.containers.run( self.config[self.LOGSTASH_SECTION][self.LOGSTASH_IMAGE], volumes={ self.config[self.LOGSTASH_SECTION][self.LOGSTASH_CONF]: { 'bind': '/usr/share/logstash/config/', 'mode': 'rw' } }, name=self.config[self.LOGSTASH_SECTION][ self.LOGSTASH_CONTAINER], ports={ "5000": self.config[self.LOGSTASH_SECTION][self.LOGSTASH_PORT], "9600": "9300" }, detach=True, restart_policy={ "Name": "on-failure", "MaximumRetryCount": 5 }) except docker.errors.ContainerError as err: print("The container exits with a non-zero exit code. \n{}".format( str(err))) raise err except docker.errors.ImageNotFound as err: print("The specified image does not exist. \n{}".format(str(err))) raise err except docker.errors.APIError as err: print("The server returns an error. \n{}".format(str(err))) raise err except KeyError as err: print("Key not present. \n{}".format(str(err))) raise err return
def setup_ldap(self): if not check_root(): self.logger.error("Please run the program using sudo privileges") raise PermissionDeniedException( "Permission Denied. Run with admin rights.") try: self.pull_image() self.client.containers.run( self.config[self.LDAP_SECTION][self.LDAP_IMAGE], name=self.config[self.LDAP_SECTION][self.LDAP_CONTAINER], environment={ "LDAP_ORGANISATION": "abzooba", "LDAP_DOMAIN": "abzooba.com", "LDAP_ADMIN_PASSWORD": "******" }, ports={ "389": "389", "636": "636" }, detach=True, restart_policy={ "Name": "on-failure", "MaximumRetryCount": 5 }) self.logger.info("Ldap docker service successfully started") except docker.errors.ContainerError as err: self.logger.error( "The container exits with a non-zero exit code. \n{}".format( str(err))) raise err except docker.errors.ImageNotFound as err: self.logger.error( "The specified image does not exist. \n{}".format(str(err))) raise err except docker.errors.APIError as err: self.logger.error("The server returns an error. \n{}".format( str(err))) raise err except KeyError as err: self.logger.error("Key not present. \n{}".format(str(err))) raise err return
def setup_elastic_search(self): if not check_root(): print("Please run the program using sudo privileges") raise PermissionDeniedException( "Permission Denied. Run with admin rights.") try: self.pull_image() self.client.containers.run( self.config[self.ELASTIC_SECTION][self.ELASTIC_IMAGE], volumes={ self.config[self.ELASTIC_SECTION][self.ELASTIC_SEARCH_DUMP_NAME]: { 'bind': '/usr/share/elasticsearch/data/', 'mode': 'rw' } }, environment={"discovery.type": "single-node"}, ports={ "9200": self.config[self.ELASTIC_SECTION][self.ELASTIC_PORT] }, name=self.config[self.ELASTIC_SECTION][self.ELASTIC_CONTAINER], detach=True, restart_policy={ "Name": "on-failure", "MaximumRetryCount": 5 }) except docker.errors.ContainerError as err: print("The container exits with a non-zero exit code. \n{}".format( str(err))) raise err except docker.errors.ImageNotFound as err: print("The specified image does not exist. \n{}".format(str(err))) raise err except docker.errors.APIError as err: print("The server returns an error. \n{}".format(str(err))) raise err except KeyError as err: print("Key not present. \n{}".format(str(err))) raise err return
def setup_kibana(self): if not check_root(): print("Please run the program using sudo privileges") raise PermissionDeniedException("Permission Denied. Run with admin rights.") try: self.pull_image() self.client.containers.run(self.config[self.KIBANA_SECTION][self.KIBANA_IMAGE], environment={"ELASTICSEARCH_URL": self.config[self.KIBANA_SECTION][self.ELASTIC_SEARCH_IP]}, ports={"5601":self.config[self.KIBANA_SECTION][self.KIBANA_PORT]}, name= self.config[self.KIBANA_SECTION][self.KIBANA_CONTAINER], detach=True, restart_policy={"Name": "on-failure", "MaximumRetryCount": 5}) except docker.errors.ContainerError as err: print("The container exits with a non-zero exit code. \n{}".format(str(err))) raise err except docker.errors.ImageNotFound as err: print("The specified image does not exist. \n{}".format(str(err))) raise err except docker.errors.APIError as err: print("The server returns an error. \n{}".format(str(err))) raise err except KeyError as err: print("Key not present. \n{}".format(str(err))) raise err return