{"action":"created","comment":{"url":"https://api.github.com/repos/LogRhythm/kibana/pulls/comments/59083056","id":59083056,"diff_hunk":"@@ -0,0 +1,103 @@\n+# File: loadAssets.py\n+#\n+# Author: Craig Cogdill\n+\n+import logging\n+import logging.handlers\n+import json\n+import time\n+from elasticsearch import Elasticsearch\n+from os import listdir\n+from os.path import isfile, join, splitext\n+log_filename = \"/var/log/probe/pythonKibanaStartup.log\"\n+logging.basicConfig(filename=log_filename,\n+                    level=logging.DEBUG,\n+                    format='%(asctime)s %(levelname)s:  %(message)s',\n+                    datefmt='%Y/%m/%d %H:%M:%S')\n+rotating_handler = logging.handlers.RotatingFileHandler(log_filename, \n+                                                        maxBytes=10485760,\n+                                                        backupCount=5)\n+es = Elasticsearch(timeout=5, max_retries=5, retry_on_timeout=True)\n+\n+kibana_version = \"4.1.4\"\n+\n+resources = \"/usr/local/kibana-\" + kibana_version + \"-linux-x64/resources\"\n+dashboards_path = resources + \"/dashboards\" \n+visualizations_path = resources + \"/visualizations\" \n+searches_path = resources + \"/searches\" \n+\n+dashboard_type = \"dashboard\"\n+visualization_type = \"visualization\"\n+search_type = \"search\"\n+\n+kibana_index = \".kibana\"\n+indent_level = 3\n+\n+def create_document(es_index, es_type, es_id, es_body):\n+    return json.dumps(es.create(index=es_index,\n+                                doc_type=es_type,\n+                                id=es_id,\n+                                body=es_body),\n+                      indent=indent_level)\n+\n+def create_document_from_file(es_index, es_type, es_id, path_to_updated_json):\n+    content = read_json_from_file(path_to_updated_json)\n+    create_document(es_index, es_type, es_id, content)\n+\n+def get_es_id(filename):\n+    return splitext(filename)[0]\n+\n+def delete_document(es_index, es_type, es_id):\n+    es.delete(es_index, es_type, es_id)\n+\n+def read_json_from_file(file):\n+    with open(file) as file_raw:    \n+        return json.load(file_raw)\n+\n+def get_version_of_file(file):\n+    return read_json_from_file(file)['version']\n+\n+def update_existing_document(es_index, es_type, es_id, path_to_updated_json):\n+    delete_document(es_index, es_type, es_id)\n+    create_document_from_file(es_index, es_type, es_id, path_to_updated_json)\n+\n+def get_request_as_json(es_index, es_type, es_id):\n+    return json.loads(json.dumps(es.get(index=es_index, doc_type=es_type, id=es_id)))\n+\n+\n+def load_assets(es_index, es_type, path_to_files, files):\n+    for file in files:\n+        logging.debug(\"--------- \" + file + \" ---------\")\n+        full_file_path = path_to_files + \"/\" + file\n+        es_id = get_es_id(file)\n+        if (es.exists(index=es_index, doc_type=es_type, id=es_id)):\n+            get_response_json = get_request_as_json(es_index, es_type, es_id)\n+            version_of_disk_file = get_version_of_file(full_file_path)\n+            version_of_es_file = get_response_json['_source']['version']\n+            if (version_of_disk_file > version_of_es_file):\n+                logging.info(\"File \\\"\" + str(file) + \"\\\" is outdated and requires update from version \" + str(version_of_es_file) +\n+                             \" to version \" + str(version_of_disk_file) + \". Updating it now...\")\n+                update_existing_document(es_index, es_type, es_id, full_file_path)\n+            else:\n+                logging.info(\"Current version of file \\\"\" + str(file) + \"\\\" in Elasticsearch is up-to-date. Version: \" + str(version_of_es_file))\n+        else:\n+            logging.info(\"File \\\"\" + str(file) + \"\\\" doesn't exist in Elasticsearch. Creating it now...\")\n+            create_document_from_file(es_index, es_type, es_id, full_file_path)\n+\n+\n+\n+\n+# ----------------- MAIN -----------------","path":"scripts/loadAssets.py","position":90,"original_position":90,"commit_id":"1f4f2d0904e0b93331773fd973c67de04e5cf4c5","original_commit_id":"1f4f2d0904e0b93331773fd973c67de04e5cf4c5","user":{"login":"shwetabhandare","id":7604636,"avatar_url":"https://avatars.githubusercontent.com/u/7604636?v=3","gravatar_id":"","url":"https://api.github.com/users/shwetabhandare","html_url":"https://github.com/shwetabhandare","followers_url":"https://api.github.com/users/shwetabhandare/followers","following_url":"https://api.github.com/users/shwetabhandare/following{/other_user}","gists_url":"https://api.github.com/users/shwetabhandare/gists{/gist_id}","starred_url":"https://api.github.com/users/shwetabhandare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shwetabhandare/subscriptions","organizations_url":"https://api.github.com/users/shwetabhandare/orgs","repos_url":"https://api.github.com/users/shwetabhandare/repos","events_url":"https://api.github.com/users/shwetabhandare/events{/privacy}","received_events_url":"https://api.github.com/users/shwetabhandare/received_events","type":"User","site_admin":false},"body":"highly recommended:\r\nhttps://docs.python.org/2/library/__main__.html\r\n\r\nReason:\r\nhttp://stackoverflow.com/questions/4041238/why-use-def-main","created_at":"2016-04-08T20:16:52Z","updated_at":"2016-04-08T20:16:52Z","html_url":"https://github.com/LogRhythm/kibana/pull/36#discussion_r59083056","pull_request_url":"https://api.github.com/repos/LogRhythm/kibana/pulls/36","_links":{"self":{"href":"https://api.github.com/repos/LogRhythm/kibana/pulls/comments/59083056"},"html":{"href":"https://github.com/LogRhythm/kibana/pull/36#discussion_r59083056"},"pull_request":{"href":"https://api.github.com/repos/LogRhythm/kibana/pulls/36"}}},"pull_request":{"url":"https://api.github.com/repos/LogRhythm/kibana/pulls/36","id":65839330,"html_url":"https://github.com/LogRhythm/kibana/pull/36","diff_url":"https://github.com/LogRhythm/kibana/pull/36.diff","patch_url":"https://github.com/LogRhythm/kibana/pull/36.patch","issue_url":"https://api.github.com/repos/LogRhythm/kibana/issues/36","number":36,"state":"open","locked":false,"title":"Kibana setup with Python","user":{"login":"craig-cogdill","id":10603412,"avatar_url":"https://avatars.githubusercontent.com/u/10603412?v=3","gravatar_id":"","url":"https://api.github.com/users/craig-cogdill","html_url":"https://github.com/craig-cogdill","followers_url":"https://api.github.com/users/craig-cogdill/followers","following_url":"https://api.github.com/users/craig-cogdill/following{/other_user}","gists_url":"https://api.github.com/users/craig-cogdill/gists{/gist_id}","starred_url":"https://api.github.com/users/craig-cogdill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craig-cogdill/subscriptions","organizations_url":"https://api.github.com/users/craig-cogdill/orgs","repos_url":"https://api.github.com/users/craig-cogdill/repos","events_url":"https://api.github.com/users/craig-cogdill/events{/privacy}","received_events_url":"https://api.github.com/users/craig-cogdill/received_events","type":"User","site_admin":false},"body":"Insert index pattern, make it the default index pattern, load all of the dashboards/viz/searches on kibana startup","created_at":"2016-04-08T19:59:18Z","updated_at":"2016-04-08T20:16:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"861c6320724911dcacbaa84152600b31d3d128fe","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/LogRhythm/kibana/pulls/36/commits","review_comments_url":"https://api.github.com/repos/LogRhythm/kibana/pulls/36/comments","review_comment_url":"https://api.github.com/repos/LogRhythm/kibana/pulls/comments{/number}","comments_url":"https://api.github.com/repos/LogRhythm/kibana/issues/36/comments","statuses_url":"https://api.github.com/repos/LogRhythm/kibana/statuses/1f4f2d0904e0b93331773fd973c67de04e5cf4c5","head":{"label":"craig-cogdill:4.1.4_NM_PythonScriptForInserting","ref":"4.1.4_NM_PythonScriptForInserting","sha":"1f4f2d0904e0b93331773fd973c67de04e5cf4c5","user":{"login":"craig-cogdill","id":10603412,"avatar_url":"https://avatars.githubusercontent.com/u/10603412?v=3","gravatar_id":"","url":"https://api.github.com/users/craig-cogdill","html_url":"https://github.com/craig-cogdill","followers_url":"https://api.github.com/users/craig-cogdill/followers","following_url":"https://api.github.com/users/craig-cogdill/following{/other_user}","gists_url":"https://api.github.com/users/craig-cogdill/gists{/gist_id}","starred_url":"https://api.github.com/users/craig-cogdill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craig-cogdill/subscriptions","organizations_url":"https://api.github.com/users/craig-cogdill/orgs","repos_url":"https://api.github.com/users/craig-cogdill/repos","events_url":"https://api.github.com/users/craig-cogdill/events{/privacy}","received_events_url":"https://api.github.com/users/craig-cogdill/received_events","type":"User","site_admin":false},"repo":{"id":52915682,"name":"kibana","full_name":"craig-cogdill/kibana","owner":{"login":"craig-cogdill","id":10603412,"avatar_url":"https://avatars.githubusercontent.com/u/10603412?v=3","gravatar_id":"","url":"https://api.github.com/users/craig-cogdill","html_url":"https://github.com/craig-cogdill","followers_url":"https://api.github.com/users/craig-cogdill/followers","following_url":"https://api.github.com/users/craig-cogdill/following{/other_user}","gists_url":"https://api.github.com/users/craig-cogdill/gists{/gist_id}","starred_url":"https://api.github.com/users/craig-cogdill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craig-cogdill/subscriptions","organizations_url":"https://api.github.com/users/craig-cogdill/orgs","repos_url":"https://api.github.com/users/craig-cogdill/repos","events_url":"https://api.github.com/users/craig-cogdill/events{/privacy}","received_events_url":"https://api.github.com/users/craig-cogdill/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/craig-cogdill/kibana","description":"Kibana","fork":true,"url":"https://api.github.com/repos/craig-cogdill/kibana","forks_url":"https://api.github.com/repos/craig-cogdill/kibana/forks","keys_url":"https://api.github.com/repos/craig-cogdill/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/craig-cogdill/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/craig-cogdill/kibana/teams","hooks_url":"https://api.github.com/repos/craig-cogdill/kibana/hooks","issue_events_url":"https://api.github.com/repos/craig-cogdill/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/craig-cogdill/kibana/events","assignees_url":"https://api.github.com/repos/craig-cogdill/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/craig-cogdill/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/craig-cogdill/kibana/tags","blobs_url":"https://api.github.com/repos/craig-cogdill/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/craig-cogdill/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/craig-cogdill/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/craig-cogdill/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/craig-cogdill/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/craig-cogdill/kibana/languages","stargazers_url":"https://api.github.com/repos/craig-cogdill/kibana/stargazers","contributors_url":"https://api.github.com/repos/craig-cogdill/kibana/contributors","subscribers_url":"https://api.github.com/repos/craig-cogdill/kibana/subscribers","subscription_url":"https://api.github.com/repos/craig-cogdill/kibana/subscription","commits_url":"https://api.github.com/repos/craig-cogdill/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/craig-cogdill/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/craig-cogdill/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/craig-cogdill/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/craig-cogdill/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/craig-cogdill/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/craig-cogdill/kibana/merges","archive_url":"https://api.github.com/repos/craig-cogdill/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/craig-cogdill/kibana/downloads","issues_url":"https://api.github.com/repos/craig-cogdill/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/craig-cogdill/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/craig-cogdill/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/craig-cogdill/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/craig-cogdill/kibana/labels{/name}","releases_url":"https://api.github.com/repos/craig-cogdill/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/craig-cogdill/kibana/deployments","created_at":"2016-03-01T22:41:19Z","updated_at":"2016-03-01T22:41:23Z","pushed_at":"2016-04-08T20:00:55Z","git_url":"git://github.com/craig-cogdill/kibana.git","ssh_url":"git@github.com:craig-cogdill/kibana.git","clone_url":"https://github.com/craig-cogdill/kibana.git","svn_url":"https://github.com/craig-cogdill/kibana","homepage":"https://www.elastic.co/products/kibana","size":184946,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"LogRhythm:4.1.4_NM","ref":"4.1.4_NM","sha":"2f34eb186a294737868641dcbc56f9b22007e810","user":{"login":"LogRhythm","id":4572303,"avatar_url":"https://avatars.githubusercontent.com/u/4572303?v=3","gravatar_id":"","url":"https://api.github.com/users/LogRhythm","html_url":"https://github.com/LogRhythm","followers_url":"https://api.github.com/users/LogRhythm/followers","following_url":"https://api.github.com/users/LogRhythm/following{/other_user}","gists_url":"https://api.github.com/users/LogRhythm/gists{/gist_id}","starred_url":"https://api.github.com/users/LogRhythm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LogRhythm/subscriptions","organizations_url":"https://api.github.com/users/LogRhythm/orgs","repos_url":"https://api.github.com/users/LogRhythm/repos","events_url":"https://api.github.com/users/LogRhythm/events{/privacy}","received_events_url":"https://api.github.com/users/LogRhythm/received_events","type":"Organization","site_admin":false},"repo":{"id":52397048,"name":"kibana","full_name":"LogRhythm/kibana","owner":{"login":"LogRhythm","id":4572303,"avatar_url":"https://avatars.githubusercontent.com/u/4572303?v=3","gravatar_id":"","url":"https://api.github.com/users/LogRhythm","html_url":"https://github.com/LogRhythm","followers_url":"https://api.github.com/users/LogRhythm/followers","following_url":"https://api.github.com/users/LogRhythm/following{/other_user}","gists_url":"https://api.github.com/users/LogRhythm/gists{/gist_id}","starred_url":"https://api.github.com/users/LogRhythm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LogRhythm/subscriptions","organizations_url":"https://api.github.com/users/LogRhythm/orgs","repos_url":"https://api.github.com/users/LogRhythm/repos","events_url":"https://api.github.com/users/LogRhythm/events{/privacy}","received_events_url":"https://api.github.com/users/LogRhythm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/LogRhythm/kibana","description":"Kibana","fork":true,"url":"https://api.github.com/repos/LogRhythm/kibana","forks_url":"https://api.github.com/repos/LogRhythm/kibana/forks","keys_url":"https://api.github.com/repos/LogRhythm/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/LogRhythm/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/LogRhythm/kibana/teams","hooks_url":"https://api.github.com/repos/LogRhythm/kibana/hooks","issue_events_url":"https://api.github.com/repos/LogRhythm/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/LogRhythm/kibana/events","assignees_url":"https://api.github.com/repos/LogRhythm/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/LogRhythm/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/LogRhythm/kibana/tags","blobs_url":"https://api.github.com/repos/LogRhythm/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/LogRhythm/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/LogRhythm/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/LogRhythm/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/LogRhythm/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/LogRhythm/kibana/languages","stargazers_url":"https://api.github.com/repos/LogRhythm/kibana/stargazers","contributors_url":"https://api.github.com/repos/LogRhythm/kibana/contributors","subscribers_url":"https://api.github.com/repos/LogRhythm/kibana/subscribers","subscription_url":"https://api.github.com/repos/LogRhythm/kibana/subscription","commits_url":"https://api.github.com/repos/LogRhythm/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/LogRhythm/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/LogRhythm/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/LogRhythm/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/LogRhythm/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/LogRhythm/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/LogRhythm/kibana/merges","archive_url":"https://api.github.com/repos/LogRhythm/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/LogRhythm/kibana/downloads","issues_url":"https://api.github.com/repos/LogRhythm/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/LogRhythm/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/LogRhythm/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/LogRhythm/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/LogRhythm/kibana/labels{/name}","releases_url":"https://api.github.com/repos/LogRhythm/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/LogRhythm/kibana/deployments","created_at":"2016-02-23T22:43:02Z","updated_at":"2016-03-01T23:09:27Z","pushed_at":"2016-04-08T20:00:55Z","git_url":"git://github.com/LogRhythm/kibana.git","ssh_url":"git@github.com:LogRhythm/kibana.git","clone_url":"https://github.com/LogRhythm/kibana.git","svn_url":"https://github.com/LogRhythm/kibana","homepage":"https://www.elastic.co/products/kibana","size":231016,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":2,"forks":7,"open_issues":2,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/LogRhythm/kibana/pulls/36"},"html":{"href":"https://github.com/LogRhythm/kibana/pull/36"},"issue":{"href":"https://api.github.com/repos/LogRhythm/kibana/issues/36"},"comments":{"href":"https://api.github.com/repos/LogRhythm/kibana/issues/36/comments"},"review_comments":{"href":"https://api.github.com/repos/LogRhythm/kibana/pulls/36/comments"},"review_comment":{"href":"https://api.github.com/repos/LogRhythm/kibana/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/LogRhythm/kibana/pulls/36/commits"},"statuses":{"href":"https://api.github.com/repos/LogRhythm/kibana/statuses/1f4f2d0904e0b93331773fd973c67de04e5cf4c5"}}}}