如何客製化 Opserver - 使用不同帳號密碼來監控多台 Windows Server

之前文章 如何使用 Opserver 來監控 Windows Server 介紹該怎麼設定 Opserver 來監控 Windows Server,但我們也發現只能使用同一組帳號密碼

注意事項:目前我只用到 WMI,所以修改是針對 WMI 來調整,bosun 與 orion 暫不適用(其實是我還不會用 bosunorion)

文章大綱

  1. 下載 Opserver
  2. 修改原始碼
  3. 修改 Windows Server 監控設定

下載 Opserver

  1. clone

  2. 解壓縮至硬碟

修改原始碼

  1. 修改 Opserver.Core\Data\Dashboard\Providers\DashboardDataProvider.cs

    • 修改 public abstract class DashboardDataProvider<TSettings> : DashboardDataProvider where TSettings : class, IProviderSettings

      • 將 Settings 改成可以吃多筆

        public IEnumerable<TSettings> Settings { get; protected set; }
        
      • DashboardDataProvider 建構式參數改成可吃多筆

        protected DashboardDataProvider(TSettings settings) : base(settings)
        
    • 修改 public abstract class DashboardDataProvider : PollNode, IIssuesProvider

      • DashboardDataProvider 建構式參數改成可吃多筆,指定名稱

        protected DashboardDataProvider(IProviderSettings settings) : base(settings.Name + "Dashboard")
        {
            Name = settings.Name;
        }
        
    • 詳細修改內容請參考 GitHub

  2. 排除以下檔案(exclude from project - 沒用到相關功能避免造成編譯不過)

    • Opserver.Core\Data\Dashboard\Providers\BosunDataProvider.cs
    • Opserver.Core\Data\Dashboard\Providers\OrionDataProvider.cs
    • Opserver.Core\Data\Dashboard\Providers\BosunDataProvider.Metrics.cs
    • Opserver.Core\Data\Dashboard\Providers\BosunDataProvider.Nodes.cs
  3. 修改 Opserver.Core\Data\Dashboard\DashboardModule.cs

    • DashboardModule 建構式迴圈取值多一層

      foreach (var p in providers.All)
      {
          if (p!=null)
          {
              foreach (var item in p)
              {
                  item?.Normalize();
              }   
          }
      }
      
    • 將使用到 bosunorion 部份移除

      //if (providers.Bosun != null)
      //    Providers.Add(new BosunDataProvider(providers.Bosun));
      //if (providers.Orion != null)
      //    Providers.Add(new OrionDataProvider(providers.Orion));
      
    • 詳細修改內容請參考 GitHub

  4. 修改 Opserver.Core\Data\Dashboard\Providers\WmiDataProvider.cs

    • 修改地方太多,大意就是把原本吃單一設定改為吃多組設定
    • 詳細修改內容請參考 GitHub
  5. 修改 Opserver.Core\Monitoring\Wmi.cs

    • 將原本取一次帳號密碼的動作改為每次連線都取當下設定
    • 詳細修改內容請參考 GitHub
  6. 修改 Opserver.Core\Settings\DashboardSettings.Providers.cs

    • 將設定改為多組資料
    • 詳細修改內容請參考 GitHub

修改 Windows Server 監控設定

  • providers –> wmi 改使用 array

    "providers": {
        "wmi": [
        {
            "nodes": [ "192.168.1.30" ],
            "staticDataTimeoutSeconds": 300,
            "dynamicDataTimeoutSeconds": 5,
            "historyHours": 2,
            "Username": "ad1\\yowko1",
            "Password": "password1"
        },
        {
            "nodes": [ "10.11.2.55" ],
            "staticDataTimeoutSeconds": 300,
            "dynamicDataTimeoutSeconds": 5,
            "historyHours": 2,
            "Username": "ad2\\yowko2",
            "Password": "password2"
        },
        {
            "nodes": [ "localhost" ],
            "staticDataTimeoutSeconds": 300,
            "dynamicDataTimeoutSeconds": 5,
            "historyHours": 2
        }
        ]
    },
    
  • 監控結果

    1RESULT

參考資料

  1. Opserver GitHub
  2. Yowko’s Repository(GitHub)