{"action":"created","comment":{"url":"https://api.github.com/repos/saltstack/salt/pulls/comments/177139276","pull_request_review_id":106958011,"id":177139276,"diff_hunk":"@@ -2286,7 +2288,85 @@ def _disabled(funs):\n     return ret\n \n \n-def event(tagmatch='*',\n+@with_deprecated(globals(), \"Fluorine\")\n+def event(tagmatch='.*',\n+          count=-1,\n+          quiet=False,\n+          sock_dir=None,\n+          pretty=False,\n+          node='minion'):\n+    r'''\n+    Watch Salt's event bus and block until the given tag is matched\n+\n+    .. versionadded:: 2016.3.0\n+\n+    This is useful for utilizing Salt's event bus from shell scripts or for\n+    taking simple actions directly from the CLI.\n+\n+    Enable debug logging to see ignored events.\n+\n+    :param tagmatch: the event is written to stdout for each tag that matches\n+        this regular expression.\n+    :param count: this number is decremented for each event that matches the\n+        ``tagmatch`` parameter; pass ``-1`` to listen forever.\n+    :param quiet: do not print to stdout; just block\n+    :param sock_dir: path to the Salt master's event socket file.\n+    :param pretty: Output the JSON all on a single line if ``False`` (useful\n+        for shell tools); pretty-print the JSON output if ``True``.\n+    :param node: Watch the minion-side or master-side event bus.\n+\n+    CLI Example:\n+\n+    .. code-block:: bash\n+\n+        salt-call --local state.event pretty=True\n+    '''\n+    try:\n+        patt = re.compile(tagmatch)\n+    except:\n+        raise SaltInvocationError(\n+            'Invalid regular expression \"{0}\" given as parameter \"tagmatch\"'.format(tagmatch)\n+        )\n+\n+    sevent = salt.utils.event.get_event(\n+            node,\n+            sock_dir or __opts__['sock_dir'],\n+            __opts__['transport'],\n+            opts=__opts__,\n+            listen=True)\n+\n+    we_are_counting = True if count > -1 else False\n+\n+    while True:\n+        ret = sevent.get_event(full=True, auto_reconnect=True)\n+        if ret is None:\n+            continue\n+\n+        if patt.search(ret['tag']) is not None:\n+            if not quiet:\n+                salt.utils.stringutils.print_cli(\n+                    str('{0}\\t{1}').format(  # future lint: blacklisted-function\n+                        salt.utils.stringutils.to_str(ret['tag']),\n+                        salt.utils.json.dumps(\n+                            ret['data'],\n+                            sort_keys=pretty,\n+                            indent=None if not pretty else 4)\n+                    )\n+                )\n+                sys.stdout.flush()\n+\n+            if we_are_counting:\n+                count -= 1\n+                if count == 0:\n+                    break\n+                log.debug('Remaining event matches: %s', count)\n+\n+        else:\n+            log.debug('Skipping event tag: %s', ret['tag'])\n+            continue","path":"salt/modules/state.py","position":96,"original_position":96,"commit_id":"4ed404b19f57e77873b2c67f272720f84e2a35bb","original_commit_id":"4ed404b19f57e77873b2c67f272720f84e2a35bb","user":{"login":"isbm","id":1073714,"avatar_url":"https://avatars2.githubusercontent.com/u/1073714?v=4","gravatar_id":"","url":"https://api.github.com/users/isbm","html_url":"https://github.com/isbm","followers_url":"https://api.github.com/users/isbm/followers","following_url":"https://api.github.com/users/isbm/following{/other_user}","gists_url":"https://api.github.com/users/isbm/gists{/gist_id}","starred_url":"https://api.github.com/users/isbm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isbm/subscriptions","organizations_url":"https://api.github.com/users/isbm/orgs","repos_url":"https://api.github.com/users/isbm/repos","events_url":"https://api.github.com/users/isbm/events{/privacy}","received_events_url":"https://api.github.com/users/isbm/received_events","type":"User","site_admin":false},"body":"It continues anyway, no need for this.","created_at":"2018-03-26T15:44:28Z","updated_at":"2018-03-26T15:58:00Z","html_url":"https://github.com/saltstack/salt/pull/46656#discussion_r177139276","pull_request_url":"https://api.github.com/repos/saltstack/salt/pulls/46656","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/saltstack/salt/pulls/comments/177139276"},"html":{"href":"https://github.com/saltstack/salt/pull/46656#discussion_r177139276"},"pull_request":{"href":"https://api.github.com/repos/saltstack/salt/pulls/46656"}}},"pull_request":{"url":"https://api.github.com/repos/saltstack/salt/pulls/46656","id":176686787,"html_url":"https://github.com/saltstack/salt/pull/46656","diff_url":"https://github.com/saltstack/salt/pull/46656.diff","patch_url":"https://github.com/saltstack/salt/pull/46656.patch","issue_url":"https://api.github.com/repos/saltstack/salt/issues/46656","number":46656,"state":"open","locked":false,"title":"Replace fnmatch with re for tag matching in state.event()","user":{"login":"samilaine","id":5918819,"avatar_url":"https://avatars2.githubusercontent.com/u/5918819?v=4","gravatar_id":"","url":"https://api.github.com/users/samilaine","html_url":"https://github.com/samilaine","followers_url":"https://api.github.com/users/samilaine/followers","following_url":"https://api.github.com/users/samilaine/following{/other_user}","gists_url":"https://api.github.com/users/samilaine/gists{/gist_id}","starred_url":"https://api.github.com/users/samilaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samilaine/subscriptions","organizations_url":"https://api.github.com/users/samilaine/orgs","repos_url":"https://api.github.com/users/samilaine/repos","events_url":"https://api.github.com/users/samilaine/events{/privacy}","received_events_url":"https://api.github.com/users/samilaine/received_events","type":"User","site_admin":false},"body":"### What does this PR do?\r\n\r\nThis PR replaces the old fnmatch-style matching for tags in `state.event()` with re-style matching.\r\n\r\nThe merits of replacing `fnmatch` with `re` are discussed in #46554. The general, albeit sparse, consensus seemed to be that this is the way to go. It's definitely a cleaner way than using try/expect to figure out whether or not `tagmatch` parameter contains a regular expression, and if it doesn't, to fall back to `fnmatch` -- it's hard to see how the resulting behaviour would be obvious for a user simply typoing a regular expression.\r\n\r\nThis PR contains code using the `@with_deprecated` decorator, which is broken in the branch `develop` at the time of opening this PR. So, this PR depends on #46602 being merged before or `@with_deprecated` getting fixed in some other way.\r\n\r\n### What issues does this PR fix or reference?\r\n\r\nSometimes it gets rather tedious to debug event-related problems (ie. broken orchestrator states and so on) on a master which is really busy (200+ events per second) without a decent matching capability to filter events. Using regular expressions to filter events displayed makes the life of an administrator a tad easier.\r\n\r\n### Previous Behavior\r\n\r\nThe function `state.event()` used fnmatch to filter events.\r\n\r\n### New Behavior\r\n\r\nThe function `state.event()` uses re to filter events.\r\n\r\n### Tests written?\r\n\r\nNo (because I couldn't make heads or tails of the testing documentation -- any/all tutors and mentors are welcome to share their wisdom on the unit-testing\r\nsystem should use mocks and whatnot).\r\n\r\n### Commits signed with GPG?\r\n\r\nNo","created_at":"2018-03-22T06:31:30Z","updated_at":"2018-03-26T15:58:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dacb9d48003a1aeb3c9f6f2752718bfe5f2d552f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[{"name":"team-core","id":1734030,"slug":"team-core","description":"Merge access to all core saltstack repos (including raet, libnacl, and the like)","privacy":"closed","url":"https://api.github.com/teams/1734030","members_url":"https://api.github.com/teams/1734030/members{/member}","repositories_url":"https://api.github.com/teams/1734030/repos","permission":"pull"}],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/saltstack/salt/pulls/46656/commits","review_comments_url":"https://api.github.com/repos/saltstack/salt/pulls/46656/comments","review_comment_url":"https://api.github.com/repos/saltstack/salt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/46656/comments","statuses_url":"https://api.github.com/repos/saltstack/salt/statuses/4ed404b19f57e77873b2c67f272720f84e2a35bb","head":{"label":"samilaine:add-rx-matching-for-modules-and-runners-statepy","ref":"add-rx-matching-for-modules-and-runners-statepy","sha":"4ed404b19f57e77873b2c67f272720f84e2a35bb","user":{"login":"samilaine","id":5918819,"avatar_url":"https://avatars2.githubusercontent.com/u/5918819?v=4","gravatar_id":"","url":"https://api.github.com/users/samilaine","html_url":"https://github.com/samilaine","followers_url":"https://api.github.com/users/samilaine/followers","following_url":"https://api.github.com/users/samilaine/following{/other_user}","gists_url":"https://api.github.com/users/samilaine/gists{/gist_id}","starred_url":"https://api.github.com/users/samilaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samilaine/subscriptions","organizations_url":"https://api.github.com/users/samilaine/orgs","repos_url":"https://api.github.com/users/samilaine/repos","events_url":"https://api.github.com/users/samilaine/events{/privacy}","received_events_url":"https://api.github.com/users/samilaine/received_events","type":"User","site_admin":false},"repo":{"id":123589695,"name":"salt","full_name":"samilaine/salt","owner":{"login":"samilaine","id":5918819,"avatar_url":"https://avatars2.githubusercontent.com/u/5918819?v=4","gravatar_id":"","url":"https://api.github.com/users/samilaine","html_url":"https://github.com/samilaine","followers_url":"https://api.github.com/users/samilaine/followers","following_url":"https://api.github.com/users/samilaine/following{/other_user}","gists_url":"https://api.github.com/users/samilaine/gists{/gist_id}","starred_url":"https://api.github.com/users/samilaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samilaine/subscriptions","organizations_url":"https://api.github.com/users/samilaine/orgs","repos_url":"https://api.github.com/users/samilaine/repos","events_url":"https://api.github.com/users/samilaine/events{/privacy}","received_events_url":"https://api.github.com/users/samilaine/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/samilaine/salt","description":"Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here: ","fork":true,"url":"https://api.github.com/repos/samilaine/salt","forks_url":"https://api.github.com/repos/samilaine/salt/forks","keys_url":"https://api.github.com/repos/samilaine/salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samilaine/salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samilaine/salt/teams","hooks_url":"https://api.github.com/repos/samilaine/salt/hooks","issue_events_url":"https://api.github.com/repos/samilaine/salt/issues/events{/number}","events_url":"https://api.github.com/repos/samilaine/salt/events","assignees_url":"https://api.github.com/repos/samilaine/salt/assignees{/user}","branches_url":"https://api.github.com/repos/samilaine/salt/branches{/branch}","tags_url":"https://api.github.com/repos/samilaine/salt/tags","blobs_url":"https://api.github.com/repos/samilaine/salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samilaine/salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samilaine/salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/samilaine/salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samilaine/salt/statuses/{sha}","languages_url":"https://api.github.com/repos/samilaine/salt/languages","stargazers_url":"https://api.github.com/repos/samilaine/salt/stargazers","contributors_url":"https://api.github.com/repos/samilaine/salt/contributors","subscribers_url":"https://api.github.com/repos/samilaine/salt/subscribers","subscription_url":"https://api.github.com/repos/samilaine/salt/subscription","commits_url":"https://api.github.com/repos/samilaine/salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/samilaine/salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/samilaine/salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/samilaine/salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/samilaine/salt/contents/{+path}","compare_url":"https://api.github.com/repos/samilaine/salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samilaine/salt/merges","archive_url":"https://api.github.com/repos/samilaine/salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samilaine/salt/downloads","issues_url":"https://api.github.com/repos/samilaine/salt/issues{/number}","pulls_url":"https://api.github.com/repos/samilaine/salt/pulls{/number}","milestones_url":"https://api.github.com/repos/samilaine/salt/milestones{/number}","notifications_url":"https://api.github.com/repos/samilaine/salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samilaine/salt/labels{/name}","releases_url":"https://api.github.com/repos/samilaine/salt/releases{/id}","deployments_url":"https://api.github.com/repos/samilaine/salt/deployments","created_at":"2018-03-02T14:33:41Z","updated_at":"2018-03-02T14:33:57Z","pushed_at":"2018-03-22T06:29:12Z","git_url":"git://github.com/samilaine/salt.git","ssh_url":"git@github.com:samilaine/salt.git","clone_url":"https://github.com/samilaine/salt.git","svn_url":"https://github.com/samilaine/salt","homepage":"https://repo.saltstack.com/","size":210492,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"saltstack:develop","ref":"develop","sha":"7423e9886d921ede5712655802dffe46eb8a3f8a","user":{"login":"saltstack","id":1147473,"avatar_url":"https://avatars3.githubusercontent.com/u/1147473?v=4","gravatar_id":"","url":"https://api.github.com/users/saltstack","html_url":"https://github.com/saltstack","followers_url":"https://api.github.com/users/saltstack/followers","following_url":"https://api.github.com/users/saltstack/following{/other_user}","gists_url":"https://api.github.com/users/saltstack/gists{/gist_id}","starred_url":"https://api.github.com/users/saltstack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saltstack/subscriptions","organizations_url":"https://api.github.com/users/saltstack/orgs","repos_url":"https://api.github.com/users/saltstack/repos","events_url":"https://api.github.com/users/saltstack/events{/privacy}","received_events_url":"https://api.github.com/users/saltstack/received_events","type":"Organization","site_admin":false},"repo":{"id":1390248,"name":"salt","full_name":"saltstack/salt","owner":{"login":"saltstack","id":1147473,"avatar_url":"https://avatars3.githubusercontent.com/u/1147473?v=4","gravatar_id":"","url":"https://api.github.com/users/saltstack","html_url":"https://github.com/saltstack","followers_url":"https://api.github.com/users/saltstack/followers","following_url":"https://api.github.com/users/saltstack/following{/other_user}","gists_url":"https://api.github.com/users/saltstack/gists{/gist_id}","starred_url":"https://api.github.com/users/saltstack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saltstack/subscriptions","organizations_url":"https://api.github.com/users/saltstack/orgs","repos_url":"https://api.github.com/users/saltstack/repos","events_url":"https://api.github.com/users/saltstack/events{/privacy}","received_events_url":"https://api.github.com/users/saltstack/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/saltstack/salt","description":"Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here: ","fork":false,"url":"https://api.github.com/repos/saltstack/salt","forks_url":"https://api.github.com/repos/saltstack/salt/forks","keys_url":"https://api.github.com/repos/saltstack/salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/saltstack/salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/saltstack/salt/teams","hooks_url":"https://api.github.com/repos/saltstack/salt/hooks","issue_events_url":"https://api.github.com/repos/saltstack/salt/issues/events{/number}","events_url":"https://api.github.com/repos/saltstack/salt/events","assignees_url":"https://api.github.com/repos/saltstack/salt/assignees{/user}","branches_url":"https://api.github.com/repos/saltstack/salt/branches{/branch}","tags_url":"https://api.github.com/repos/saltstack/salt/tags","blobs_url":"https://api.github.com/repos/saltstack/salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/saltstack/salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/saltstack/salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/saltstack/salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/saltstack/salt/statuses/{sha}","languages_url":"https://api.github.com/repos/saltstack/salt/languages","stargazers_url":"https://api.github.com/repos/saltstack/salt/stargazers","contributors_url":"https://api.github.com/repos/saltstack/salt/contributors","subscribers_url":"https://api.github.com/repos/saltstack/salt/subscribers","subscription_url":"https://api.github.com/repos/saltstack/salt/subscription","commits_url":"https://api.github.com/repos/saltstack/salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/saltstack/salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/saltstack/salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/saltstack/salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/saltstack/salt/contents/{+path}","compare_url":"https://api.github.com/repos/saltstack/salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/saltstack/salt/merges","archive_url":"https://api.github.com/repos/saltstack/salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/saltstack/salt/downloads","issues_url":"https://api.github.com/repos/saltstack/salt/issues{/number}","pulls_url":"https://api.github.com/repos/saltstack/salt/pulls{/number}","milestones_url":"https://api.github.com/repos/saltstack/salt/milestones{/number}","notifications_url":"https://api.github.com/repos/saltstack/salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/saltstack/salt/labels{/name}","releases_url":"https://api.github.com/repos/saltstack/salt/releases{/id}","deployments_url":"https://api.github.com/repos/saltstack/salt/deployments","created_at":"2011-02-20T20:16:56Z","updated_at":"2018-03-26T14:25:28Z","pushed_at":"2018-03-26T15:52:31Z","git_url":"git://github.com/saltstack/salt.git","ssh_url":"git@github.com:saltstack/salt.git","clone_url":"https://github.com/saltstack/salt.git","svn_url":"https://github.com/saltstack/salt","homepage":"https://repo.saltstack.com/","size":211621,"stargazers_count":8699,"watchers_count":8699,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4065,"mirror_url":null,"archived":false,"open_issues_count":3662,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":4065,"open_issues":3662,"watchers":8699,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/saltstack/salt/pulls/46656"},"html":{"href":"https://github.com/saltstack/salt/pull/46656"},"issue":{"href":"https://api.github.com/repos/saltstack/salt/issues/46656"},"comments":{"href":"https://api.github.com/repos/saltstack/salt/issues/46656/comments"},"review_comments":{"href":"https://api.github.com/repos/saltstack/salt/pulls/46656/comments"},"review_comment":{"href":"https://api.github.com/repos/saltstack/salt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/saltstack/salt/pulls/46656/commits"},"statuses":{"href":"https://api.github.com/repos/saltstack/salt/statuses/4ed404b19f57e77873b2c67f272720f84e2a35bb"}},"author_association":"NONE"}}
{"actor":{"display_login":"isbm"}}