Splunk Search

サーチ結果からアラーム的にブラウザ側で音(MP3)を再生することはできますか。

syazaki_splunk
Splunk Employee
Splunk Employee

リモートワークがフォーカスされてきており、オペレーションセンターに勤務ができない状況が続いております。このため、今までアラームをパトランプでセンター側で鳴らしていたのですが、自宅でオペレーションすることになり、自宅側でもアラームを認識したいと思っています。メールではできることは認識していますが、サーチ結果に対して音を鳴らしてアラームに反応したいと思っております。具体的にどのようなダッシュボードにすればよいかガイド頂けますでしょうか。

Labels (1)
Tags (1)
0 Karma
1 Solution

syazaki_splunk
Splunk Employee
Splunk Employee

自己解決しました。

以下サンプルコードです。

①MP3をSplunkサーバ側に配置します。
場所は、$SPLUNK_HOME/etc/apps/[MYAPP]/appserver/static です。デフォルトではappserver/staticというディレクトは
ありませんので、作成ください。MYAPPは任意のAppを指定します。これらのディレクトやMP3は他のSplunkと同様の権限を設定ください。
今回は、beep-01.mp3 から、beep-05.mp3までの5つのファイルを配置していることを想定しています。

ーーー以下サンプルダッシュボードのXMLの説明ですーーー
②サーチ部分

| makeresults | eval ttt=_time | rex field=ttt "(?P<last>.)$"
| eval saisei=case(last==1,"beep-01",last==2,"beep-02",last==3,"beep-03",last==4,"beep-04",last>=5,"beep-05")
| table saisei

サンプルですが、サーチの結果が数字であった場合、1ならbeep-01,2ならbeep-02のようにcaseで指定します。
判断をしたいサーチをいれていただき、結果によって返す値からmp3の音声をしていすればよいと思います。

③サーチの結果をトークンに入れる部分

          <finalized>
            <set token="tok_result">$result.saisei$</set>
          </finalized>

上記②のサーチの結果が、saiseiというフィールドに入りますので、これをトークンにするため、$result.saisei$を利用します。
結果として、tok_resultトークンにサーチ結果が入ります。例,beep-01とかbeep-02など。

④音を鳴らす部分

  <row depends="$hidden$">
    <panel>
      <html>
      <body>
        <iframe src="/static/app/[MYAPP]/$tok_result$.mp3" allow="autoplay" style="display:none" id="iframeAudio"/>
        <audio src="/static/app/[MYAPP]/$tok_result$.mp3" autoplay="autoplay"/>
      </body>
    </html>
    </panel>
  </row>

これで画面を更新するたびに音がなります。

※ただし、ブラウザ依存があるようです。
Chrome の設定を、「設定」→「プライバシーとセキュリティ」→「サイトの設定」→「音声」で許可サイトに Splunk サーバのドメインを追加したら出ました。ブラウザ毎に設定方法が違うと思われます。細かく試していませんが、Firefox と Safari のどちらも音出ません。設定方法を探す必要がありそうです。

  <label>検索結果をトークンにしてその結果から別々の音声を流す</label>
  <row>
    <panel>
      <title>$tok_result$</title>
      <single>
        <search>
          <finalized>
            <set token="tok_result">$result.saisei$</set>
          </finalized>
          <query>| makeresults | eval ttt=_time | rex field=ttt "(?P<last>.)$"
| eval saisei=case(last==1,"beep-01",last==2,"beep-02",last==3,"beep-03",last==4,"beep-04",last>=5,"beep-05") | table saisei</query>
          <earliest>$earliest$</earliest>
          <latest>$latest$</latest>
        </search>
        <option name="colorBy">value</option>
        <option name="colorMode">none</option>
        <option name="drilldown">none</option>
        <option name="numberPrecision">0</option>
        <option name="rangeColors">["0x53a051", "0x0877a6", "0xf8be34", "0xf1813f", "0xdc4e41"]</option>
        <option name="rangeValues">[0,30,70,100]</option>
        <option name="refresh.display">progressbar</option>
        <option name="showSparkline">1</option>
        <option name="showTrendIndicator">1</option>
        <option name="trellis.enabled">0</option>
        <option name="trellis.scales.shared">1</option>
        <option name="trellis.size">medium</option>
        <option name="trendColorInterpretation">standard</option>
        <option name="trendDisplayMode">absolute</option>
        <option name="unitPosition">after</option>
        <option name="useColors">0</option>
        <option name="useThousandSeparators">1</option>
      </single>
    </panel>
  </row>
  <row depends="$hidden$">
    <panel>
      <html>
      <body>
        <iframe src="/static/app/SplunkDojo/$tok_result$.mp3" allow="autoplay" style="display:none" id="iframeAudio"/>
        <audio src="/static/app/SplunkDojo/$tok_result$.mp3" autoplay="autoplay"/>
      </body>
    </html>
    </panel>
  </row>
</dashboard>

View solution in original post

syazaki_splunk
Splunk Employee
Splunk Employee

自己解決しました。

以下コードサンプルです。

<dashboard>
  <label>検索結果をトークンにしてその結果から別々の音声を流す</label>
  <row>
    <panel>
      <title>$tok_result$</title>
      <single>
        <search>
          <finalized>
            <set token="tok_result">$result.saisei$</set>
          </finalized>
          <query>| makeresults | eval ttt=_time | rex field=ttt "(?P<last>.)$"
| eval saisei=case(last==1,"beep-01",last==2,"beep-02",last==3,"beep-03",last==4,"beep-04",last>=5,"beep-05") | table saisei</query>
          <earliest>$earliest$</earliest>
          <latest>$latest$</latest>
        </search>
        <option name="colorBy">value</option>
        <option name="colorMode">none</option>
        <option name="drilldown">none</option>
        <option name="numberPrecision">0</option>
        <option name="rangeColors">["0x53a051", "0x0877a6", "0xf8be34", "0xf1813f", "0xdc4e41"]</option>
        <option name="rangeValues">[0,30,70,100]</option>
        <option name="refresh.display">progressbar</option>
        <option name="showSparkline">1</option>
        <option name="showTrendIndicator">1</option>
        <option name="trellis.enabled">0</option>
        <option name="trellis.scales.shared">1</option>
        <option name="trellis.size">medium</option>
        <option name="trendColorInterpretation">standard</option>
        <option name="trendDisplayMode">absolute</option>
        <option name="unitPosition">after</option>
        <option name="useColors">0</option>
        <option name="useThousandSeparators">1</option>
      </single>
    </panel>
  </row>
  <row depends="$hidden$">
    <panel>
      <html>
      <body>
        <iframe src="/static/app/SplunkDojo/$tok_result$.mp3" allow="autoplay" style="display:none" id="iframeAudio"/>
        <audio src="/static/app/SplunkDojo/$tok_result$.mp3" autoplay="autoplay"/>
      </body>
    </html>
    </panel>
  </row>
</dashboard>

①MP3をSplunkサーバ側に配置します。
場所は、$SPLUNK_HOME/etc/apps/[MYAPP]/appserver/static です。デフォルトではappserver/staticというディレクトは
ありませんので、作成ください。MYAPPは任意のAppを指定します。これらのディレクトやMP3は他のSplunkと同様の権限を設定ください。
今回は、beep-01.mp3 から、beep-05.mp3までの5つのファイルを配置していることを想定しています。

ーーー以下サンプルダッシュボードのXMLの説明ですーーー
②サーチ部分
| makeresults | eval ttt=_time | rex field=ttt "(?P<last>.)$"
| eval saisei=case(last==1,"beep-01",last==2,"beep-02",last==3,"beep-03",last==4,"beep-04",last>=5,"beep-05")
| table saisei

サンプルですが、サーチの結果が数字であった場合、1ならbeep-01,2ならbeep-02のようにcaseで指定します。
判断をしたいサーチをいれていただき、結果によって返す値からmp3の音声をしていすればよいと思います。

③サーチの結果をトークンに入れる部分

$result.saisei$

上記②のサーチの結果が、saiseiというフィールドに入りますので、これをトークンにするため、$result.saisei$を利用します。
結果として、tok_resultトークンにサーチ結果が入ります。例,beep-01とかbeep-02など。

④音を鳴らす部分
<row depends="$hidden$">



0 Karma

syazaki_splunk
Splunk Employee
Splunk Employee

自己解決しました。

以下サンプルコードです。

①MP3をSplunkサーバ側に配置します。
場所は、$SPLUNK_HOME/etc/apps/[MYAPP]/appserver/static です。デフォルトではappserver/staticというディレクトは
ありませんので、作成ください。MYAPPは任意のAppを指定します。これらのディレクトやMP3は他のSplunkと同様の権限を設定ください。
今回は、beep-01.mp3 から、beep-05.mp3までの5つのファイルを配置していることを想定しています。

ーーー以下サンプルダッシュボードのXMLの説明ですーーー
②サーチ部分

| makeresults | eval ttt=_time | rex field=ttt "(?P<last>.)$"
| eval saisei=case(last==1,"beep-01",last==2,"beep-02",last==3,"beep-03",last==4,"beep-04",last>=5,"beep-05")
| table saisei

サンプルですが、サーチの結果が数字であった場合、1ならbeep-01,2ならbeep-02のようにcaseで指定します。
判断をしたいサーチをいれていただき、結果によって返す値からmp3の音声をしていすればよいと思います。

③サーチの結果をトークンに入れる部分

          <finalized>
            <set token="tok_result">$result.saisei$</set>
          </finalized>

上記②のサーチの結果が、saiseiというフィールドに入りますので、これをトークンにするため、$result.saisei$を利用します。
結果として、tok_resultトークンにサーチ結果が入ります。例,beep-01とかbeep-02など。

④音を鳴らす部分

  <row depends="$hidden$">
    <panel>
      <html>
      <body>
        <iframe src="/static/app/[MYAPP]/$tok_result$.mp3" allow="autoplay" style="display:none" id="iframeAudio"/>
        <audio src="/static/app/[MYAPP]/$tok_result$.mp3" autoplay="autoplay"/>
      </body>
    </html>
    </panel>
  </row>

これで画面を更新するたびに音がなります。

※ただし、ブラウザ依存があるようです。
Chrome の設定を、「設定」→「プライバシーとセキュリティ」→「サイトの設定」→「音声」で許可サイトに Splunk サーバのドメインを追加したら出ました。ブラウザ毎に設定方法が違うと思われます。細かく試していませんが、Firefox と Safari のどちらも音出ません。設定方法を探す必要がありそうです。

  <label>検索結果をトークンにしてその結果から別々の音声を流す</label>
  <row>
    <panel>
      <title>$tok_result$</title>
      <single>
        <search>
          <finalized>
            <set token="tok_result">$result.saisei$</set>
          </finalized>
          <query>| makeresults | eval ttt=_time | rex field=ttt "(?P<last>.)$"
| eval saisei=case(last==1,"beep-01",last==2,"beep-02",last==3,"beep-03",last==4,"beep-04",last>=5,"beep-05") | table saisei</query>
          <earliest>$earliest$</earliest>
          <latest>$latest$</latest>
        </search>
        <option name="colorBy">value</option>
        <option name="colorMode">none</option>
        <option name="drilldown">none</option>
        <option name="numberPrecision">0</option>
        <option name="rangeColors">["0x53a051", "0x0877a6", "0xf8be34", "0xf1813f", "0xdc4e41"]</option>
        <option name="rangeValues">[0,30,70,100]</option>
        <option name="refresh.display">progressbar</option>
        <option name="showSparkline">1</option>
        <option name="showTrendIndicator">1</option>
        <option name="trellis.enabled">0</option>
        <option name="trellis.scales.shared">1</option>
        <option name="trellis.size">medium</option>
        <option name="trendColorInterpretation">standard</option>
        <option name="trendDisplayMode">absolute</option>
        <option name="unitPosition">after</option>
        <option name="useColors">0</option>
        <option name="useThousandSeparators">1</option>
      </single>
    </panel>
  </row>
  <row depends="$hidden$">
    <panel>
      <html>
      <body>
        <iframe src="/static/app/SplunkDojo/$tok_result$.mp3" allow="autoplay" style="display:none" id="iframeAudio"/>
        <audio src="/static/app/SplunkDojo/$tok_result$.mp3" autoplay="autoplay"/>
      </body>
    </html>
    </panel>
  </row>
</dashboard>
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...