用powershell脚本实现zabbix LLD 监控IIS站点

简介:

需求:

生产环境中需要实现IIS 站点监控自动化,需要获取到站点名和站点进程的PID。有了站点名可以用windows内置的key获取相关监控项的值。例如站点的get、post请求数,站点的版本信息等。但是还需要监控IIS站点的SQL连接数,这需要IIS站点被访问,并且有SQL进程。然后通过进程号来判断是各个站点的SQL连接数。


脚本内容:

get.sitename

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$sitearray =@()
[System.Collections.ArrayList] $arraylist = $sitearray
$command =c:\windows\system32\inetsrv\appcmd.exe list vdir
foreach  ( $i  in  $command )
{
     $site = $i .split(" ")[1].split(" / ")[0].split('\" ')[1].trim( '' )
     $arraylist .insert(0, $site )
}
#echo $arraylist
$a = $arraylist .count-1
#echo $a
echo     "{`n"
echo    `t '"data"' :[
foreach  ( $i  in  0.. $a )
{
      echo `n`t`t "{"
      $web = $arraylist [ $i ]
      $dir = '"{#SITENAME}"' + ':' + '"' + $web + '"'
      echo `t`t`t $dir
      echo `t`t "}"
      if  ( $i  -lt  $a )
      {
      echo `t`t ','
      }
}
echo `t]
echo  "}"



get.site.pid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$sitearray =@()
$pidarray =@()
[System.Collections.ArrayList] $arraylist = $sitearray
[System.Collections.ArrayList] $pidlist = $pidarray
$command =c:\windows\system32\inetsrv\appcmd.exe list wp
foreach  ( $i  in  $command )
{
    $site = $i .split( ':' )[1].replace( ')' , '' )
    $pidlist .insert(0, $i .split()[1])
    $arraylist .insert(0, $site )  
}
$a = $arraylist .count-1
#echo $arraylist
#echo $pidlist
echo     "{`n" 
echo    `t '"data"' :[
foreach  ( $i  in  0.. $a )
{
      echo `n`t`t "{"
      $web = $arraylist [ $i ]
      $id = $pidlist [ $i ]
      $dir1 = '"{#WP_NAME}"' + ':' + '"' + $web + '"'
      $dir2 = '"{#WP_PID}"' + ':' + $id
      echo `t`t`t $dir1 ',' $dir2
      echo `t`t "}"
      if  ( $i  -lt  $a )
      {
      echo `t`t ','
     
}
echo `t]
echo  "}"










本文转自 曾哥最爱 51CTO博客,原文链接:http://blog.51cto.com/zengestudy/1857764,如需转载请自行联系原作者

目录
相关文章
|
4月前
|
存储 安全 Windows
PowerShell系列(六):PowerShell脚本执行策略梳理
【2月更文挑战第1篇】PowerShell 脚本执行策略用于控制何时以及何种方式执行 PowerShell 脚
|
6天前
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
|
6天前
|
Ubuntu Linux 测试技术
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
|
7天前
|
存储 Shell 容器
【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken
【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken
|
7天前
【Azure 应用服务】Azure Function 中运行Powershell 脚本,定位 -DefaultProfile 引发的错误
【Azure 应用服务】Azure Function 中运行Powershell 脚本,定位 -DefaultProfile 引发的错误
|
7天前
|
Java
【Azure 应用服务】使用PowerShell脚本上传文件至App Service目录  
【Azure 应用服务】使用PowerShell脚本上传文件至App Service目录  
|
7天前
|
Java 开发工具 Windows
【Azure Developer】调用SDK的runPowerShellScript方法,在Azure VM中执行PowerShell脚本示例
【Azure Developer】调用SDK的runPowerShellScript方法,在Azure VM中执行PowerShell脚本示例
|
7天前
|
缓存 监控 NoSQL
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
|
8天前
|
存储 数据库
【Azure 应用服务】在Azure Funciton中使用Powershell脚本函数,需要存储一些变量值如何解决?
【Azure 应用服务】在Azure Funciton中使用Powershell脚本函数,需要存储一些变量值如何解决?
|
3月前
|
存储 SQL 运维
使用PowerShell进行自动化脚本编写:入门与实战
【6月更文挑战第6天】本文介绍了PowerShell作为Windows系统管理的自动化工具,用于提升效率和减少错误。内容涵盖PowerShell基础,如变量、命令执行、管道、条件和循环语句、函数。实战案例展示了如何用PowerShell脚本进行文件备份。此外,还提及PowerShell的进阶功能,如模块、远程管理和与其他工具集成。学习和应用PowerShell能有效提升IT运维自动化水平。

推荐镜像

更多
下一篇
云函数