Windows Server 2008에서 디스크 공간 부족 경고 설정 Server 2008에서

논리 디스크 파티션의 공간이 부족 해지면 Windows Server 2008에서 전자 메일 경고를 트리거하는 쉬운 방법이 있는지 궁금합니다. DB 로그 파일로 인해 디스크 공간이 부족한 SQL 서버가 2 대 있습니다.

고마워, 라이언



답변

디스크 공간이 부족한 전자 메일 경고를 Windows Server 2008에 전송하는 간단한 방법 중 하나는 작업 스케줄러와 시스템 로그를 사용하는 것입니다. 여유 공간이 HKLM \ SYSTEM \ CurrentControlSet \ Services \ LanmanServer \ Parameters \ DiskSpaceThreshold에 지정된 백분율 아래로 떨어지면 시스템 로그에 이벤트가 기록되어 전자 메일 메시지를 보내는 작업을 트리거 할 수 있습니다.

  1. 작업 스케줄러를 열고 새 작업을 만듭니다.
  2. 작업 이름을 입력하고 “사용자 로그온 여부에 관계없이 실행”을 선택한 다음 “암호 저장 안 함”을 선택하십시오.
  3. 트리거 탭에서 새 트리거를 추가하십시오.
  4. “작업 시작”상자에서 “이벤트에서”를 선택하십시오.
  5. 로그를 “시스템”으로, 소스를 “srv”로, 이벤트 ID를 “2013”으로 설정하십시오.
  6. 조치 탭에서 새 조치를 추가하십시오.
  7. 작업을 “이메일 보내기”로 설정하고 나머지 설정을 적절히 입력하십시오.
  8. 디스크 공간 부족 이벤트가 시스템 로그에 기록 될 때 구성하려면 레지스트리 편집기를 열고 HKLM \ SYSTEM \ CurrentControlSet \ Services \ LanmanServer \ Parameters로 이동 한 다음 “DiskSpaceThreshold”라는 DWORD 값을 추가하여 원하는 백분율로 설정하십시오. 항목이 없으면 기본값은 10입니다.

답변

snmp를 통해 디스크 공간 모니터링을 별도의 nagios 인스턴스에 추가했습니다.


답변

왜 매일 스케줄 작업으로 powershell 스크립트를 실행하지 않습니까? 스크립트에서 디스크의 여유 공간이 10 % 미만인 경우 전자 메일 또는 알림을 보냅니다.

다음은 디스크의 여유 공간을 확인하기위한 코드 예입니다.

Get-Content ForEach-Object {$ ; Get-WMIObject –computername $
Win32_LogicalDisk-필터 “DriveType = 3″| ForEach-Object {$ .DeviceID; $ .FreeSpace / 1GB}}


답변

잘못된 PowerShell 구문으로 인해 두 예제가 모두 작동하지 않습니다. 다음 코드는 현재 호스트의 볼륨 크기 (PowerShell 5.0 사용)를 나열합니다.

Get-WmiObject win32_logicalDisk -filter "DriveType=3" | %{ $_.DeviceID; $_.FreeSpace/1GB }

다음 코드는 server.txt에 나열된 호스트의 볼륨 크기를 나열합니다 .

Get-Content server.txt | %{ Get-WMIObject –computername $_ Win32_LogicalDisk -filter "DriveType=3" | %{ $_.DeviceID; $_.FreeSpace/1GB } }

사이드 노트

외부 자리 표시자는 $_서버 주소를 열거하지만 내부 자리 표시자는 $_장치를 열거합니다. PowerShell 초보자에게는 빈번한 문제입니다. 내부 루프에서 서버 주소를 사용하려면 외부 루프의 새 변수에 서버 주소를 할당해야합니다.

여기에 사용 된 포럼 소프트웨어에 결함이 있습니다. 게시물 미리보기에서는 코드로 이스케이프되지 않더라도 $_올바르게 표시 됩니다 $_. 그러나 마지막 게시물은 밑줄을 제거하므로 PowerShell 예제가 잘못되었습니다.


답변

이 스크립트를 사용하여 이메일 서버를 사용하여 이메일을 보낼 수 있습니다. smtp 서버 이름을 서버 이름으로 바꾸십시오. 동일한 시스템에있는 경우 “localhost”를 사용하십시오 (smtp 서버가 작동해야합니다). 스크립트는 https://gallery.technet.microsoft.com/scriptcenter/Disk-Space-Report-Reports-98e64d65 에서도 찾을 수 있습니다.

스크립트가 로컬 드라이브에 저장되면 powershell을 사용하여 쉽게 실행하고 테스트 할 수 있습니다. 스크립트가 제대로 작동하면 Windows 작업 스케줄러를 사용하여 요구 사항에 따라 매일 또는 매시간 실행되도록 예약 할 수 있습니다. 이 기사에서는 작업 스케줄러를 사용하여 스크립트를 실행하는 방법에 대해 설명합니다.
https://www.metalogix.com/help/Content%20Matrix%20Console/SharePoint%20Edition/002_HowTo/004_SharePointActions/012_SchedulingPowerShell.htm

#############################################################################
#                                                                                                                                                     #
#  Check disk space and send an HTML report as the body of an email.                                                   #
#  Reports only disks on computers that have low disk space.                                                                 #
#  Author: Mike Carmody                                                                                                                   #
#  Some ideas extracted from Thiyagu's Exchange DiskspaceHTMLReport module.                                  #
#  Date: 8/10/2011                                                          #
#  I have not added any error checking into this script yet.                #
#                                                                           #
#                                                                           #
#############################################################################
# Continue even if there are errors
$ErrorActionPreference = "Continue";

#########################################################################################
# Items to change to make it work for you.
#
# EMAIL PROPERTIES
#  - the $users that this report will be sent to.
#  - near the end of the script the smtpserver, From and Subject.

# REPORT PROPERTIES
#  - you can edit the report path and report name of the html file that is the report.
#########################################################################################

# Set your warning and critical thresholds
$percentWarning = 15;
$percentCritcal = 10;

# EMAIL PROPERTIES
 # Set the recipients of the report.
  $users = "YourDistrolist@company.com"
    #$users = "You@company.com" # I use this for testing by uing my email address.
  #$users = "you@company.com", "manager@company.com", "etc@company.com";  # can be sent to individuals.


# REPORT PROPERTIES
 # Path to the report
  $reportPath = "D:\Jobs\DiskSpaceQuery\Reports\";

 # Report name
  $reportName = "DiskSpaceRpt_$(get-date -format ddMMyyyy).html";

# Path and Report name together
$diskReport = $reportPath + $reportName

#Set colors for table cell backgrounds
$redColor = "#FF0000"
$orangeColor = "#FBB917"
$whiteColor = "#FFFFFF"

# Count if any computers have low disk space.  Do not send report if less than 1.
$i = 0;

# Get computer list to check disk space
$computers = Get-Content "servers_c.txt";
$datetime = Get-Date -Format "MM-dd-yyyy_HHmmss";

# Remove the report if it has already been run today so it does not append to the existing report
If (Test-Path $diskReport)
    {
        Remove-Item $diskReport
    }

# Cleanup old files..
$Daysback = "-7"
$CurrentDate = Get-Date;
$DateToDelete = $CurrentDate.AddDays($Daysback);
Get-ChildItem $reportPath | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item;

# Create and write HTML Header of report
$titleDate = get-date -uformat "%m-%d-%Y - %A"
$header = "
  <html>
  <head>
  <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
  <title>DiskSpace Report</title>
  <STYLE TYPE='text/css'>
  <!--
  td {
   font-family: Tahoma;
   font-size: 11px;
   border-top: 1px solid #999999;
   border-right: 1px solid #999999;
   border-bottom: 1px solid #999999;
   border-left: 1px solid #999999;
   padding-top: 0px;
   padding-right: 0px;
   padding-bottom: 0px;
   padding-left: 0px;
  }
  body {
   margin-left: 5px;
   margin-top: 5px;
   margin-right: 0px;
   margin-bottom: 10px;
   table {
   border: thin solid #000000;
  }
  -->
  </style>
  </head>
  <body>
  <table width='100%'>
  <tr bgcolor='#CCCCCC'>
  <td colspan='7' height='25' align='center'>
  <font face='tahoma' color='#003399' size='4'><strong>AEM Environment DiskSpace Report for $titledate</strong></font>
  </td>
  </tr>
  </table>
"
 Add-Content $diskReport $header

# Create and write Table header for report
 $tableHeader = "
 <table width='100%'><tbody>
 <tr bgcolor=#CCCCCC>
    <td width='10%' align='center'>Server</td>
 <td width='5%' align='center'>Drive</td>
 <td width='15%' align='center'>Drive Label</td>
 <td width='10%' align='center'>Total Capacity(GB)</td>
 <td width='10%' align='center'>Used Capacity(GB)</td>
 <td width='10%' align='center'>Free Space(GB)</td>
 <td width='5%' align='center'>Freespace %</td>
 </tr>
"
Add-Content $diskReport $tableHeader

# Start processing disk space reports against a list of servers
  foreach($computer in $computers)
 {
 $disks = Get-WmiObject -ComputerName $computer -Class Win32_LogicalDisk -Filter "DriveType = 3"
 $computer = $computer.toupper()
  foreach($disk in $disks)
 {
  $deviceID = $disk.DeviceID;
        $volName = $disk.VolumeName;
  [float]$size = $disk.Size;
  [float]$freespace = $disk.FreeSpace;
  $percentFree = [Math]::Round(($freespace / $size) * 100, 2);
  $sizeGB = [Math]::Round($size / 1073741824, 2);
  $freeSpaceGB = [Math]::Round($freespace / 1073741824, 2);
        $usedSpaceGB = $sizeGB - $freeSpaceGB;
        $color = $whiteColor;

# Set background color to Orange if just a warning
 if($percentFree -lt $percentWarning)
  {
    $color = $orangeColor

# Set background color to Orange if space is Critical
      if($percentFree -lt $percentCritcal)
        {
        $color = $redColor
       }

 # Create table data rows
    $dataRow = "
  <tr>
        <td width='10%'>$computer</td>
  <td width='5%' align='center'>$deviceID</td>
  <td width='15%' >$volName</td>
  <td width='10%' align='center'>$sizeGB</td>
  <td width='10%' align='center'>$usedSpaceGB</td>
  <td width='10%' align='center'>$freeSpaceGB</td>
  <td width='5%' bgcolor=`'$color`' align='center'>$percentFree</td>
  </tr>
"
Add-Content $diskReport $dataRow;
Write-Host -ForegroundColor DarkYellow "$computer $deviceID percentage free space = $percentFree";
    $i++
  }
 }
}

# Create table at end of report showing legend of colors for the critical and warning
 $tableDescription = "
 </table><br><table width='20%'>
 <tr bgcolor='White'>
    <td width='10%' align='center' bgcolor='#FBB917'>Warning less than 15% free space</td>
 <td width='10%' align='center' bgcolor='#FF0000'>Critical less than 10% free space</td>
 </tr>
"
  Add-Content $diskReport $tableDescription
 Add-Content $diskReport "</body></html>"

# Send Notification if alert $i is greater then 0
if ($i -gt 0)
{
    foreach ($user in $users)
{
        Write-Host "Sending Email notification to $user"

  $smtpServer = "MySMTPServer"
  $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
  $msg = New-Object Net.Mail.MailMessage
  $msg.To.Add($user)
        $msg.From = "myself@company.com"
  $msg.Subject = "Environment DiskSpace Report for $titledate"
        $msg.IsBodyHTML = $true
        $msg.Body = get-content $diskReport
  $smtp.Send($msg)
        $body = ""
    }
  }

답변

스크립트를 수정했습니다. 예를 들어 server.txt라는 텍스트 파일을 만들고 ip 주소 또는 servernames를 포함 시키면 다음 스크립트를 실행할 수 있습니다.

Get-Content server.txt | foreach-object {Get-WmiObject -ComputerName 192.168.22.208 win32_logicalDisk -filter “DriveType = 3″| ForEach-Object {$ .DeviceID; $ .FreeSpace / 1GB}}

감사합니다, 루이스


답변

Get-Content server.txt | foreach-object {Get-WmiObject -ComputerName xx.xx.xx.xx win32_logicalDisk -filter “DriveType = 3″| forEach-Object {$ .DeviceID; $ .FreeSpace / 1GB}}