当前位置: 首页 > news >正文

PowerShell 实现企业微信机器人推送消息

前言企业微信机器人

在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.ps1Get-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

输出结果

以下是虚拟机测试,部分没有显示出来原因没有获取到具体的硬件信息可以忽略

http://www.lryc.cn/news/31415.html

相关文章:

  • IDEA集成Git就是这么简单
  • springBoot 事务基本原理
  • HBuilderX无线连接真机
  • idea初学笔记
  • C++核心编程<类和对象>(4)
  • 编写http workshop脚本从网页缓存里解析音乐
  • 当数字孪生遇上轨道交通,会有什么新发展?
  • 原理底层计划--分布式事务
  • Hive总结
  • docker环境下安装jenkins
  • Shifu基础功能:设备接入
  • 基于Java+SpringBoot+Vue+Redis+RabbitMq的鲜花商城
  • 蓝桥杯真题(解码)小白入!
  • 并发包中的ConcurrentLinkedQueue和LinkedBlockingQueue有什么区别?
  • 分享四个前端Web3D动画库在Threejs中使用的动画库以及优缺点附地址
  • 谷歌浏览器和火狐浏览器永久禁用缓存【一劳永逸的解决方式】
  • kibana查看日志
  • JS 异步接口调用介绍
  • 5.深入理解HttpSecurity的设计
  • opencv-python numpy常见的api接口汇总(持续更新)
  • 概率论小课堂:伯努利实验(正确理解随机性,理解现实概率和理想概率的偏差)
  • 加密功能实现
  • 大数据项目实战之数据仓库:用户行为采集平台——第1章 数据仓库概念
  • NTP对时服务器(NTP电子时钟)在生物制药业应用
  • JPA 之 QueryDSL-JPA 使用指南
  • 如何找回回收站删除的视频?这三种方法可以试试
  • FPGA_边沿监测理解
  • 41 42Ping-Pong操作
  • 保护你的数据安全,了解网络安全法!
  • 什么是CatGPT-使用效果如何-