• 使用を開始する
  • 関連ドキュメント

アラートのカスタマイズとフィルタリングのための正規表現

この記事では、Jira Service Management Cloud の一部のお客様に段階的に展開されている、Jira Service Management でネイティブに利用できる新しいアラート機能を取り上げています。ご利用のサイトにはまだ表示されていないか、利用できない可能性があります。

Jira Service Management は Java に似た正規表現を使用して、情報のフィルタリングと抽出を強化して、統合、アラート・ポリシー、コールバックで使用可能な動的プロパティを定義します。多くの場合、正規表現を使用することによって必要な情報を抽出できます。たとえば、[一致] 演算子でフィルタリング・ルールを定義して、extract 文字列処理メソッドでアラート・フィールドに設定するデータを抽出します。

「一致」ルールでフィルターするための正規表現

The conditions with Matches operator are met if whole string value matches the pattern of the given regular expression. If the type of the input value is List, then the condition is matched if at least one of the list items matches the given regular expression. With this operator, you can define complex filtering in a single condition rule and reduce your dependency on already-defined condition operators. Read more about condition operators.

[一致] 条件演算子の利用に適した一般的なユースケースの例は次のとおりです。

AND/OR で複数のルールを結合する

件名に "Daily Report (日次レポート)"、説明に Critical (クリティカル)、Error (エラー)、または Down (ダウン) が含まれている場合にメール統合でアラートを作成するには、[一致] ルール内で次の正規表現を使用できます。.*(Critical|Error|Down).*

類似ルールの重複を防止する

To notify again of an alert if its description starts with one of the server names server1, server2, ..., server100, you can use the following regular expression within a single Matches rule instead of 20 Starts with rules: ^(server(100|[1-9]\d?)).*

複雑なルールを定義する

アラート・メッセージに有効なメール・アドレスが含まれている場合に Webhook コールバックを実行するには、次の正規表現を使用します。.*(\s+.*)?([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})(\s+.*)? 

Extract 文字列処理メソッドを使用してアラート フィールドを設定するための正規表現

You can use the extract string processing method to extract desired matching group according to a given regular expression to set into an alert field. Read more about string processing methods.

extract メソッドを使用して必要な結果を得るには、キャプチャ・グループの理解が必要な場合があります。これには次の 2 つの定義があります。

  • field_name.extract(reg_exp): 指定された正規表現の最初の括弧で囲まれたセクション (グループ) に一致する文字列の一部を指定します。文字列が指定された正規表現に一致しない場合は、空の文字列を返します。指定された正規表現が文字列と一致するが、括弧で囲まれたセクションを含まない場合は、文字列全体を返します。

  • field_name.extract(reg_exp, index): 指定された正規表現の index 番目の括弧で囲まれたセクション (グループ) に一致する文字列を指定します。文字列が指定された正規表現に一致しない場合は、空の文字列を返します。指定された正規表現が文字列と一致するが、index の数以上の括弧で囲まれたセクションを含まない場合は、文字列全体を返します。

グループの取得については、こちらをご覧ください。

次に、両方のメソッド定義を使用する例をいくつか示します。

message: Host: First Second

message.extract(/Host: (\S+)/)

 = First

message.extract(/Host: (\S+) (\S+)/)

 = First

message.extract(/Host:(\S+)/)

 = 空の値

message.extract(/Host: (\S+)/, 0)

 = Host: First Second

message.extract(/Host: (\S+)/, 1)

 = First

message.extract(/Host: (\S+)/, 2)

 = Host: First

message.extract(/Host: (\S+) (\S+)/, 2)

 = Second

message.extract(/(\S)+/)

 = Host:

message.extract(/\S+/)

 = Host:

description: some value server3

description.extract(/(server(100|[1-9]\d?))/)

= server3

description.extract(/(server(100|[1-9]\d?))/, 1)

 = server3

description.extract(/(server(100|[1-9]\d?))/, 2)

 = 3

description.extract(/(server(100|[1-9]\d?))/, 3)

 = server3

description.extract(/server(100|[1-9]\d?)/, 0)

 = server3

description.extract(/server(100|[1-9]\d?)/, 1)

 = 3

description.extract(/server(100|[1-9]\d?)/, 2)

 = server3

description.extract(/(server(100|[1-9]\d?))/, 2)

 = 3

extract メソッドを使用して目的のアラート・フィールドを設定するには、次のいずれかのパターンでアラート・プロパティにテキストを書き込みます。

{{ field_name.extract(/reg_exp/) }}

{{ field_name.extract(/reg_exp/, group_number) }}

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。