前言企业微信机器人
在ARMS告警管理中创建企业微信机器人后,您可以在通知策略中指定对应的企业微信群用于接收告警。当通知策略的匹配规则被触发时,系统会自动向您指定的企业微信群发送告警通知。企业微信群收到通知后,您可以在企业微信群中对告警进行管理。
通过接口实现在群里发送告警或提醒类的消息通知。
一键实现企业微信机器人推送消息
- 实现获取系统信息,实际需要可行参考以下进行更改满足。
- Invoke-RestMethod #将 HTTP 或 HTTPS 请求发送到 RESTful Web 服务,参考
- Write-Output #将指定的 对象写入管道。 如果
Write-Output
是管道中的最后一个命令,则对象将显示在控制台中。参考 - Get-WmiObject 获取系统的信息,以下获取部分系统信息参数,所详细的可参考
Win32_Processor // CPU 处理器
Win32_PhysicalMemory // 物理内存
Win32_Keyboard // 键盘
Win32_PointingDevice // 点输入设备,如鼠标
Win32_DiskDrive // 硬盘驱动器
Win32_CDROMDrive // 光盘驱动器
Win32_BaseBoard // 主板
Win32_BIOS // BIOS 芯片
Win32_ParallelPort // 并口
Win32_SerialPort // 串口
Win32_SoundDevice // 多媒体设置
Win32_USBController // USB 控制器
Win32_NetworkAdapter // 网络适配器
Win32_NetworkAdapterConfiguration // 网络适配器设置
Win32_Printer // 打印机
Win32_PrinterConfiguration // 打印机设置
Win32_PrintJob // 打印机任务
Win32_TCPIPPrinterPort // 打印机端口
Win32_POTSModem // MODEM
Win32_POTSModemToSerialPort // MODEM 端口
Win32_DesktopMonitor // 显示器
Win32_VideoController // 显卡细节。
Win32_VideoSettings // 显卡支持的显示模式。
Win32_TimeZone // 时区
Win32_SystemDriver // 驱动程序
Win32_DiskPartition // 磁盘分区
Win32_LogicalDisk // 逻辑磁盘
Win32_LogicalMemoryConfiguration // 逻辑内存配置
Win32_PageFile // 系统页文件信息
Win32_PageFileSetting // 页文件设置
Win32_BootConfiguration // 系统启动配置
Win32_OperatingSystem // 操作系统信息
Win32_StartupCommand // 系统自动启动程序
Win32_Service // 系统安装的服务
Win32_Group // 系统管理组
Win32_GroupUser // 系统组帐号
Win32_UserAccount // 用户帐号
Win32_Process // 系统进程
Win32_Thread // 系统线程
Win32_Share // 共享
Win32_NetworkClient // 已安装的网络客户端
Win32_NetworkProtocol // 已安装的网络协议 ######>
- $webhook 输入主机的企业机器人地址
- $content = Write-Output ""Win_version: $Win_version_Names" `n #格式注意,`n换行的意思,$Win_version_Names获取变量的值
- $body 实现格式如文本模式text,Markdown格式 企业微信机器人创建
powershell-install-Windwos-Enterprise-wechat-module.ps1
<# Powershell Install Windwos version
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ _____ _____ _ _ _ +
+ | __ \ / ____| | | | |+
+ | |__) |____ _____ _ _| (___ | |__ ___| | |+
+ | ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | | | (_) \ V V / __/ | ____) | | | | __/ | |+
+ |_| \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
# Powershell Install Windwos version
# .\powershell-install-Windwos-Enterprise-wechat-module.ps1
Get-WmiObject Manage system hardware and feature information
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-wmiobject?view=powershell-5.1
Get-WmiObject -List #Lists the WMI classes
#>
#Enterprise wechat robot address
$webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX_YOU_企业微信机器人地址"
#Obtain the Windows host system version
$Win_version = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption
$Win_version_Names = echo $Win_version
#Get all IP addresses of the local host
$Win_ip = foreach($ipv4 in (ipconfig) -like '*IPv4*') { ($ipv4 -split ' : ')[-1]}
#Get the host name
$Win_hostname = Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty Name
#Gets the native memory size in Gb, keeping two decimal places
$mem = "{0:N2}GB" -f (((Get-WmiObject -Class Win32_PhysicalMemory).capacity | Measure-Object -Sum).sum /1gb)
#Gets the number of local memory modules
$slot_mem = ((Get-WmiObject -Class Win32_PhysicalMemory).capacity | Measure-Object -Sum).count
#Gets the native memory manufacturer
$Manufacturer_mem = (Get-WmiObject -Class Win32_PhysicalMemory).Manufacturer
#Get the local free memory, in Gb, keep two decimal places
$freemem_men = "{0:N2}GB" -f ((Get-WmiObject -Class Win32_OperatingSystem).FreePhysicalMemory /1mb)
#Gets the current host time
$Win_time = Get-Counter '\Processor(_Total)\% Processor Time' | Select-Object -ExpandProperty Timestamp
#Output gets the information, noting that $Win_version_Names gets the value of the variable using Write-Output `n, which means a newline
$content = Write-Output ""Win_version: $Win_version_Names" `n "Mem_siza: $mem" `n "Win_host_ip: $Win_ip" `n "Win_hostname: $Win_hostname" `n "slot_mem: $slot_mem" `n "Manufacturer_mem: $Manufacturer_mem" `n "freemem_men: $freemem_men" `n "Win_time: $Win_time ""
$body = "{
`"msgtype`":`"text`",
`"text`":{
`"content`":`"$content`",
`"mentioned_list`":[`"jason`"]
}
}"
Write-Host "The variable value obtained is transferred to the enterprise wechat robot" -ForegroundColor Green
Invoke-RestMethod $webhook -ContentType "application/json;charset=utf-8" -Method Post -Body $body
执行
.\powershell-install-Windwos-Enterprise-wechat-module.ps1