def get_all_nodes_health(): """ This function will use the proliantutils library module "get_host_health_data" to derive the health status of the following components 'BIOS, Fans, Temperature Sensors, Battery, Processor, Memory, Network, Storage. If the health status of all component is ok then overall health of the physical node is returned as "OK" """ try: result = get_all_nodes() final = {} for key, value in result.items(): dict_object = {} if type(value) == type(dict()): v = list(value.values()) ilo_client = client.IloClient(v[1], v[2], v[3]) dict_object = ilo_client.get_host_health_data() q = JSONParser(dict_object) bios = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/BIOS_HARDWARE/STATUS" ) fans = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/FANS/STATUS") temperature = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/TEMPERATURE/STATUS" ) battery = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/BATTERY/STATUS" ) processor = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/PROCESSOR/STATUS" ) memory = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/MEMORY/STATUS" ) network = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/NETWORK/STATUS" ) storage = q.dict_query( "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/STORAGE/STATUS" ) total_health = [bios, fans, temperature, battery, processor,\ memory, network, storage] result1 = len(set(total_health)) == 1 if result1: final[v[0]] = "OK" else: final[v[0]] = "Degraded" except: print("Unexpected error:", sys.exc_info()[0]) raise return (final)
def __init__(self, categories=None, parser=None): if categories is None: self._categories = { "Food": Food(), "Tools": Tools(), "Electronics": Electronics(), "Books": Books() } else: self._categories = categories self._parser = JSONParser() if parser is None else parser
def get_all_nodes(): """ This function will read data from the host.json and store it in the form od dictionary object """ try: result = {} p = JSONParser('hosts.json') result = p.all_data() except: print("Unexpected error:", sys.exc_info()[0]) raise return (result)
def set_environment_var(): """ This function will set the PATH and KUBECONFIG environment variables as per the user defined values in "config.json" file """ try: data = JSONParser("config.json") kubeconfig = data.query("kubeconfig_path") #path = data.query("oc_command_path") #os.environ["PATH"] += os.pathsep + os.path.join(path) os.environ["KUBECONFIG"] = kubeconfig user_env = os.environ except: print("Unexpected error:", sys.exc_info()[0]) raise return (user_env)
def get_all_node_security_status(): """ This function will use the proliantutils library module "get_current_bios_settings" to derive the status of the following BIOS configuration which are important for the security: 'secure boot status (enabled), asset tag (locked), UEFI Shell Script Verification (enabled), UEFI Shell Startup (disabled), Processor AES (enabled)" If the value of any of the configuration deviates from the recommended value, overall security status will be marked as degraded. Refer to BIOS user guide for recommended value of these configurations """ try: result = get_all_nodes() final = {} for key, value in result.items(): dict_object = {} if type(value) == type(dict()): v = list(value.values()) ilo_client = client.IloClient(v[1], v[2], v[3]) dict_object = ilo_client.get_current_bios_settings() q = JSONParser(dict_object) secure_boot_status = q.dict_query("SecureBootStatus") asset_tag = q.dict_query("AssetTagProtection") shell_script_verify = q.dict_query( "UefiShellScriptVerification") shell_startup = q.dict_query("UefiShellStartup") processor_aes = q.dict_query("ProcAes") if v[0] == "secphyworker1.sec.twentynet.local" and \ secure_boot_status.lower() == "disabled": final[v[0]] = "OK" elif secure_boot_status.lower() == "enabled" and \ asset_tag.lower() == "locked" and \ shell_script_verify.lower() == "enabled" and \ shell_startup.lower() == "disabled" and \ processor_aes.lower() == "enabled": final[v[0]] = "OK" else: final[v[0]] = "Degraded" except: print("Unexpected error:", sys.exc_info()[0]) raise return (final)
def parse_json(self, cfg, schema): set_def = lambda x, y: self.cfg[x] if self.cfg[x] != "" else y self.json = JSONParser(os.path.abspath(schema), os.path.abspath(cfg), extend_defaults=True, logger=self.logger) self.cfg = self.json.get_cfg() self.logger.debug(self.json.print_cfg()) self._from = set_def('from', None) self._to = set_def('to', None) self._cc = self.cfg['cc'] self._bcc = self.cfg['bcc'] self.smtp_server = self.cfg['smtp-server'] self.smtp_port = self.cfg['smtp-port'] self.auth = set_def('smtp-authentication', None) self.username = set_def('smtp-username', None) self.password = set_def('smtp-password', None)
def on_data(self, data): parser = JSONParser(data) try: conn = psycopg2.connect(database="twitterdb", user="******", password="******", port=5433) except: print("I am unable to connect to the database") cur = conn.cursor() try: for tweet in parser.createTweets(parser.data): try: insert_user_row(tweet.user, cur) except: pass try: insert_tweet_row(tweet, cur) for mentioned_user in tweet.mentioned_users: insert_mentioned_user_row(mentioned_user, cur) for hashtag in tweet.hashtags: try: insert_hashtag_row(hashtag, cur) hashtag_id = fetch_hashtag_id(hashtag, cur) insert_row_to_intersection_table( hashtag_id, tweet.id, cur) except: pass conn.commit() except: pass except: pass conn.commit() conn.close() return True
except AttributeError: for item in data: if "url" in item: self.urls.append(item) else: self.addItem(str(item)) self.data = data @QtCore.pyqtSlot(QtCore.QModelIndex) def cell_double_clicked_slot(self, model_index): model_row = model_index.row() # the way urls_index_row_tuple is [(urls, index)] index_row_list = [x[1] for x in self.urls_index_row_tuple] if model_row in index_row_list: tuple_index = index_row_list.index(model_row) url = self.urls_index_row_tuple[tuple_index][0] print(url) self.url_signal.emit(QtCore.QUrl(url)) if __name__ == '__main__': from PyQt5 import QtWidgets import sys app = QtWidgets.QApplication(sys.argv) #j = JSONParser("http://127.0.0.1:8000/projects/2/") j = JSONParser("http://127.0.0.1:8000/projects/2/ideas/3/") view_widget = InstanceViewWidget(data=j.data) view_widget.show() sys.exit(app.exec_())
if __name__ == '__main__': parser = argparse.ArgumentParser() # Sagemaker specific arguments. Defaults are set in the environment variables. parser.add_argument('--output-data-dir', type=str, default=os.environ['SM_OUTPUT_DATA_DIR']) parser.add_argument('--model-dir', type=str, default=os.environ['SM_MODEL_DIR']) args = parser.parse_args() preprocessor = JSONParser() joblib.dump(preprocessor, os.path.join(args.model_dir, "model.joblib")) print("saved model!") def input_fn(input_data, content_type): if content_type == 'application/json': return json.loads(input_data) else: raise ValueError( "{} not supported by json_parser!".format(content_type))