PowerShell发送美观的Vsphere数据存储警报

  

豆子今天登陆Vsphere VCenter的时候,无意中发现有数据存储的警报信息,个别数据存储的使用空间超过90%了,需要清空一下圣卷的快照。这个是运维常见的问题,那么顺便就用PowerShell写个脚本,定期检查发送邮件好了。


脚本本身很容易,但是我想让他尽量的美观一些。

之前我写过一个博文可以自定义时段的样式,http://beanxyz.blog.51cto.com/5570417/1786712,不过现在看起来有些麻烦,还是觉得找找如果有比较好看的现成的css文件可以直接调用就好了。


上网搜了搜表有哪些现成的css模板,随便找了一个https://codepen。io/不久/钢笔/vJmLWL,看着还成

下载他的css下来

 PowerShell发送美观的Vsphere数据存储警报

下载的css文件,保存在C: \ tmp目录


@import  url (https://fonts.googleapis.com/css?family=Roboto: 400500700300100);   body  {   ,,背景颜色:# 3 e94ec;   ,,字体类型:“Roboto”, helvetica,, arial,,无衬线;   ,,字体大小:16 px;   ,,粗细:400;   文本渲染才能:optimizeLegibility;   }   div.table-title  {   ,,,显示:块;   ,保证金:大敌;汽车;   ,,max-width: 600 px;   填充才能:5 px;   ,,宽度:100%;   }   .table-title  h4  {   ,,,颜色:# fafafa;   ,,,字体大小:30 px;   ,,,粗细:400;   ,,字体样式:正常;   ,,,字体类型:“Roboto”, helvetica,, arial,,无衬线;   ,,,文本阴影:1 px  1 px  1 px  rgba (0, 0, 0, 0.1);   ,,首字母:大写;   }/* * *,Table  Styles  * */.table-fill  {   背景:才能,白色;   border - radius才能:3 px;   ,,border-collapse:崩溃;   ,,身高:200 px;   ,保证金:大敌;汽车;   ,,max-width: 600 px;   填充才能:5 px;   ,,宽度:100%;   ,,不必:0,5 px  10 px  rgba (0, 0, 0, 0.1);   动画:才能,float  5 s 无限;   }   ,   th  {   颜色:# D5DDE5;才能;   背景:# 1 b1e24;才能   边界底部才能:4 px  solid  # 9 ea7af;   边境才能:1 px  solid  # 343 a45;   字体大小才能:23 px;   ,,粗细:100;   填充才能:24 px;   text-align才能:左;   ,,文本阴影:0,1 px  1 px  rgba (0, 0, 0, 0.1);   vertical-align才能:中间;   }   th: first-child  {   border-top-left-radius才能:3 px;   }   ,   th: last-child  {   border-top-right-radius才能:3 px;   边境才能:没有;   }   ,,   tr  {   ,,border-top: 1 px  solid  # C1C3D1;   边界底部——才能:1 px  solid  # C1C3D1;   颜色:# 666 b85;才能   ,,字体大小:16 px;   粗细才能:正常;   ,,文本阴影:0,1 px  1 px  rgba (256,, 256,, 256,, 0.1);   }   ,   tr: hover  td  {   背景:# 4 e5066;才能   颜色:# FFFFFF,才能   ,,border-top: 1 px  solid  # 22262 e;   边界底部才能:1 px  solid  # 22262 e;   }   ,   tr: first-child  {   border-top才能:没有;   }   tr: last-child  {   边界底部才能:没有;   }   ,   tr: nth-child(奇怪),td  {   背景:# EBEBEB;才能   }   ,   tr: nth-child(奇数):hover  td  {   背景:# 4 e5066;才能   }   tr: last-child  td: first-child  {   border-bottom-left-radius才能:3 px;   }   ,   tr: last-child  td: last-child  {   border-bottom-right-radius才能:3 px;   }   ,   td  {   背景:# FFFFFF;才能   填充才能:20 px;   text-align才能:左;   vertical-align才能:中间;   粗细才能:300;   字体大小才能:18 px;   ,,文本阴影:1 px  1 px  1 px  rgba (0, 0, 0, 0.1);   边境才能:1 px  solid  # C1C3D1;   }   道明:last-child  {   边境才能:0 px;   }   th.text-left  {   text-align才能:左;   }   th.text-center  {   ,,text-align:中心;   }   th.text-right  {   text-align:,才能正确的;   }   td.text-left  {   text-align才能:左;   }   td.text-center  {   ,,text-align:中心;   }   td.text-right  {   text-align:,才能正确的;   }


下面是正式的脚本,Set-CellColor也是别人写好的现成的,我直接拿来用了,主要功能是根据条件来更改html文件表的格子的颜色,比如某个值大于警报线就标记为红色等等。脚本中间加载Vsphere SnapIn,查询数据存储的状态,最后把结果转换为html,通过Office365发送邮件出去

PowerShell发送美观的Vsphere数据存储警报