Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Record a Windows Event Log with a custom application/source and appropriate message

Requirement

  • You want to record an event on Windows Event Log.
  • The log should be recorded with a custom application and source.
  • The message of the event should be recorded appropriately. The message should not contain the warning like The description for Event ID ( <####> ) in Source (<application name>) could not be found..

What you have to do

  1. Run the following command on PowerShell with administrator privilege. Note that you have to once register, remove, and re-register the event source with a custom log name. When you run Write-EventLog just after New-EventLog -LogName Application -Source MyLogSource, the message contained the warning above in my environment.
PS C:\> New-EventLog -LogName Application -Source MyLogSource
PS C:\> Remove-EventLog -Source MyLogSource
PS C:\> New-EventLog -LogName MyLogName -Source MyLogSource
  1. Run Write-EventLog with the ordinal user privilege.
PS C:\> Write-EventLog -LogName MyLogName -Source MyLogSource -EventID 1 -Category 0 -EntryType "Information" -Message "SOME MESSAGE"

Note (the location of events)

Note that New-EventLog adds a new entry [Application and Service Logs]-[MyLogName] on the Windows Event Viewer, but it will be empty. The Write-EventLog will add an event on [Windows Logs]-[Application]. The general information of the event will be like this:

Item Value
Log Name Application
Source MyLogSource
Event ID 1
Lelel Information
User N/A
OpCode Information
Task Category None*1
Keywords Classic
Computer (equals to the result of hostname)

Note (message table DLL and MUI files)

Some site *2*3 says you need to make a message table DLL with mc.exe, rc.exe, link.exe to suppress the message The description for Event ID ( <####> ) in Source (<application name>) could not be found. Some site also says you need MUI files for DLLs. In my environment, message table DLL doesn't work and New-EventLog solves the problem.

You cannot show fullscreen message and log-off after a time-out with shutdown.exe

Background

You can log off from Windows with shutdown.exe.

Requirement

  • You want to log off from Windows at the specified time. It should not be shut down after the log-off.
  • You want to show a fullscreen message 5 minutes before the log-off process starts so that the user can prepare to log off.

Problem

shutdown.exe /l /t 300 fails with the usage.

On the other hand, shutdown.exe /s /t 300 shuts down Windows properly with a fullscreen message and a 5-minute time-out.

Cause

It is by design. shutdown.exe cannot accept /t option with /l.

There is no out-of-the-box feature of Windows to show a fullscreen message and log-off after a time-out *1.

Note

You might use the parental control feature in Windows if you can have two or more Microsoft account. Note that parental control needs a Microsoft account for a parent and one for a child. For example, if the user account links to the employee number, you cannot make an additional account for yourself.

Windows Event Viewer Category Correspondence Table

I couldn't find the correspondence table between the value of the -Category argument (Int16) of Write-EventLog cmdlet and the category shown in Event Viewer from Microsoft.

I have run this command and viewed the result in the Event Viewer and Get-EventLog cmdlet.

0..32767 | ForEach-Object { Write-EventLog -LogName Application -Source Application -EventID $_ -EntryType Information -Category $_ -Message "SOME MESSAGE" }
Category English Japanese
0 None なし
1 Devices バイス
2 Disk ディスク
3 Printers プリンター
4 Services サービス
5 Shell シェル
6 System Event システム イベント
7 Network ネットワーク
8 (8) (8)
32767 (32767) (32767)

Note that the name of Category depends on the locale of the system. You will get Devices in English (Codepage 437) environment, while デバイス in Japanese (Codepage 932) environment.

JavaEEアプリケーションサーバに対するHTTPリクエストの流量制御が可能な箇所の候補

RHEL標準の機能のみで、外から追加のモジュール等を導入することなしに採用可能な方法の候補を列挙してみた。また商用JavaEEサーバの場合は専用の機能があるケースもありそうだが、Tomcatの場合に使える方法の候補も調べてみた。

制御箇所の候補

  • TCP/IPレベルで制御する
    • tcでQoSを指定する*1
    • firewalldのaccept limit valueを使う*2
    • nftablesのlimit rateを使う*3
  • APIゲートウェイで制御する
  • Webサーバで制御する
    • Apacheのmod_securityを使う*5
    • ServerLimitとMaxClientsを指定する
    • ProxyPassディレクティブのmaxパラメータを指定する*6
  • アプリケーションサーバで制御する
    • Tomcatの場合
      • maxThreads,maxConnectionsを指定する*7
      • SemaphoreValveを使う*8
    • その他商用JavaEEサーバ
      • JavaEEサーバの流量制御機能を使う*9
  • アプリケーション内で制御する
    • GuavaのRateLimiterを使う*10
    • bucket4jを使う*11
    • 自前で実装する*12
  • クライアント側に協力してもらう
    • レスポンスにrate limitの情報を含める*13

評価の必要な観点

  • CGNを考慮した流量制御が可能か(リクエスト送信元ポート番号が考慮可能か)
  • 同様に、RFC 6302を考慮してログが残せるか
  • URLパスごとの制御が可能か
  • 「最大○リクエスト」に加えて「N秒間に最大Mリクエスト」という制御が可能か
  • リクエスト数での制御が可能か
  • ネットワーク帯域での制御(最大○Mbpsまで許可)が可能か

Red Hat Learning Subscriptionで問題が発生した場合の問い合わせ方法

Red Hat Learning Subscription (RHLS)には問題発生時の問い合わせ手順が少なくとも下記(A)(B)(C)の3つある。差異として、問い合わせ内容の管理方法や、Red Hatから回答があったときの返信方法が異なる。メールセキュリティ製品で組織外メールアドレスへの送信に制限がかけられている場合などには(B)か(C)、特にすぐに回答が欲しい場合は(C)がよいと思われる。

(A) RHLSのトップページから問い合わせる方法

手順
  1. Red Hat Learning Subsucriptionのトップページ上部から「SUPPORT」を選択する。
  2. 「Open a Support Case」が表示される。表示された入力欄に問い合わせ内容を入力する。
結果
  • Customer Supportページにはサポートケースが追加されない。
  • 回答時間のSLAは指定できない。
  • サポートから回答があった場合、"Red Hat Training Request" から通知メールがくる。
  • メール本文中にサポートケースへのリンクがないため、返信方法が不明(メールで返信ができる?)。

(B) Customer supportでサポートケースを作る方法

手順
  1. Red Hat Customer Portal上部から「サポートケースを管理」、もしくはRed Hatのトップページ上部で「サービス&サポート」→「サポートケース」を選択する。
  2. Customer supportページから「ケースの作成」でサポートケースを作成する。
  3. 「製品」に「Red Hat Online Learning 1.0」を指定し、ケース情報に問い合わせ内容を入力する。注意事項として、コースコード(RH124とか)を入力する欄がないため、問題が発生したコースコード、および演習のタイトルをケース情報に含めること。
結果
  • Customer Supportページにサポートケースが追加される。
  • サポートケースの作成時に重大度が指定でき、重大度ごとにSLA(Lowなら2営業日、Normalなら1営業日など)が決まっている。
  • サポートから回答があった場合、"Red Hat Support" から通知メールがくる。
  • メール本文中にサポートケースへのリンクがあり、メール返信でなくとも返信が行える。

(C) RHLSのページからサポートチャットで問い合わせ

手順
  1. RHLSのトップページの右下にあるフキダシをクリックする。サポートチャットの対応時間外ではこの方法は利用できない(フキダシが表示されない)。
  2. [Send us a message]を押下すると、まずBotが応答する。サポートの必要な内容を選択肢*1
  3. 選択肢を選びおわったらサポートのスタッフとチャットで会話できる。
結果
  • Customer Supportページにはサポートケースが追加されない。必要があればサポートケースを作成するようスタッフから指示される。
  • 回答時間のSLAはないようだが、回答時間の目安はフキダシを押下した際に表示される("A few minutes")など。
  • サポートとの会話内容は、対応したスタッフごとのアドレス(と思われる)からメールで送られてくる。メールアドレスは"(名前) from Red Hat <(ユーザ名) at red-hat-hex12桁.intercom-mail.com>"で、Red Hatのメールアドレスではない。
  • メール本文中にチャットへのリンクがあり、メール返信でなくともチャットを継続できる。

*1:最初は"Expert Chat course assistance", "Status of an existing request", "Technical Support", "Exam Support"から選択し、以降は出てきた選択肢に従う