├── CHANGELOG.md ├── README.md ├── epoch-time-convert.ps1 ├── psbbix.psd1 ├── psbbix.psm1 └── zabbix-db-size-calc.ps1 /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | ##### [0.2.1] - 2019-09-22 3 | ##### Fixed 4 | - Minor fixes 5 | 6 | ##### [0.2.0] - 2019-04-14 7 | ##### Breaking change 8 | - cmdlets Get-ZabbixGroup and Set-ZabbixGroup were renamed to Get-ZabbixHostGroup and Set-ZabbixHostGroup 9 | 10 | ##### [0.2.0-alpha.7] - 2019-03-27 11 | ##### Breaking change 12 | - cmdlets Get-ZabbixGroup and Set-ZabbixGroup were renamed to Get-ZabbixHostGroup and Set-ZabbixHostGroup 13 | 14 | ##### Added 15 | - Validations to Connect-Zabbix, Disconnect-Zabbix 16 | - Custom URL path for case Zabbix frontend installed not in default https://zabbix.domain.net/zabbix, but in something like https://zabbix.domain.net or https://zabbix.domain.net/redir/zabbix 17 | 18 | ##### [0.2.0-alpha.6] - 2019-03-13 19 | ##### Breaking change 20 | - cmdlets Get-ZabbixGroup and Set-ZabbixGroup were renamed to Get-ZabbixHostGroup and Set-ZabbixHostGroup 21 | 22 | ##### Fixed 23 | - New-ZabbixSession 24 | 25 | ##### [0.2.0-alpha.5] - 2019-03-09 26 | ##### Breaking change 27 | - cmdlets Get-ZabbixGroup and Set-ZabbixGroup were renamed to Get-ZabbixHostGroup and Set-ZabbixHostGroup 28 | 29 | ##### Fixed 30 | - Mostly grammar and validation stuff 31 | 32 | ##### [0.2.0-alpha.4] - 2019-02-28 33 | ##### Breaking change 34 | - cmdlets Get-ZabbixGroup and Set-ZabbixGroup were renamed to Get-ZabbixHostGroup and Set-ZabbixHostGroup 35 | 36 | ##### Fixed 37 | - Get-ZabbixUser 38 | - Get-ZabbixUserGroup 39 | - New-ZabbixUser 40 | - Set-ZabbixUser 41 | 42 | ##### Added 43 | ```powershell 44 | New-ZabbixUserGroup 45 | Set-ZabbixUserGroup 46 | Remove-ZabbixUserGroup 47 | ``` 48 | 49 | ##### [0.2.0-alpha.3] - 2019-02-11 50 | ##### Breaking change 51 | - cmdlets Get-ZabbixGroup and Set-ZabbixGroup were renamed to Get-ZabbixHostGroup and Set-ZabbixHostGroup 52 | - However old Get-ZabbixGroup and Set-ZabbixGroup will continue to work, thank to aliases. But they will be deprecated in the future 53 | ##### Fixed 54 | - A lot of minor things 55 | 56 | ##### Added 57 | ```powershell 58 | Get-ZabbixHostInventory (experimental) 59 | Set-ZabbixHostInventory (experimental) 60 | ``` 61 | ##### [0.2.0-alpha.2] - 2019-02-05 62 | ##### Breaking change 63 | - cmdlets Get-ZabbixGroup and Set-ZabbixGroup were renamed to Get-ZabbixHostGroup and Set-ZabbixHostGroup 64 | - However old Get-ZabbixGroup and Set-ZabbixGroup will continue to work, thank to aliases. But they will be deprecated in the future 65 | ##### Fixed 66 | - Removed annoying splatting parameter: @zabSessionParams. The parameter still exist, and can be used, if needed 67 | - Connect-Zabbix 68 | - Disconnect-Zabbix 69 | - New-ZabbixHost 70 | - Set-ZabbixHost 71 | - Set-Zabbixuser 72 | - A lot of minor things 73 | ##### Added 74 | ```powershell 75 | Copy-ZabbixHost 76 | Get-ZabbixEvent 77 | Get-ZabbixHistory 78 | Get-ZabbixHostGroup 79 | Get-ZabbixMediaType 80 | Get-ZabbixProblem 81 | Import-ZabbixConfiguration 82 | New-ZabbixApplication 83 | New-ZabbixMediaType 84 | New-ZabbixTemplate 85 | Remove-ZabbixApplication 86 | Remove-ZabbixItem 87 | Remove-ZabbixMediaType 88 | Set-ZabbixApplication 89 | Set-ZabbixEvent 90 | Set-ZabbixHostGroup 91 | Set-ZabbixHostGroupAddHosts 92 | Set-ZabbixHostGroupRemoveHosts 93 | Set-ZabbixItem 94 | Set-ZabbixMaintenance 95 | Set-ZabbixMediaType 96 | Set-ZabbixTemplate 97 | ``` 98 | 99 | ##### [0.1.8] - 2017-03-03 100 | ##### Fixed 101 | - Get-ZabbixItem error when running with no parameters 102 | 103 | ##### [0.1.7-bf] - 2016-10-22 104 | ##### Fixed 105 | - Cosmetic fixes 106 | 107 | ##### [0.1.6-bf] - 2016-10-10 108 | 109 | ##### [0.1.6-bf-beta.1] - 2016-10-09 110 | ##### Added 111 | - Validations 112 | - Usability improvements 113 | 114 | ##### [0.1.6-bf-beta] - 2016-10-05 115 | ##### Added 116 | - Added Get-ZabbixHelp (gzh), for search/list useful examples within help. Pattern will be highlighted in yellow, thanks to David Mohundro's Find-String module 117 | 118 | ##### Fixed 119 | - Fixed duplicate function appearance 120 | - Fixed various functions behavior 121 | 122 | ##### [0.1.5] - 2016-09-12 123 | ##### Fixed 124 | - Fixed dot sourcing load of additional libraries 125 | 126 | ##### [0.1.4] - 2016-09-12 127 | ##### Fixed 128 | - Fixed `psbbix.psd1` for [PowerShellGallery](https://www.powershellgallery.com) 129 | 130 | ##### [0.1.3] - 2016-09-12 131 | ##### Fixed 132 | - Fixed `psbbix.psd1` for [PowerShellGallery](https://www.powershellgallery.com) 133 | 134 | ##### [0.1.2] - 2016-09-12 135 | ##### Added 136 | - Added `psbbix.psd1` for support with the [PowerShellGallery](https://www.powershellgallery.com) 137 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # psbbix 3 | Powershell Module for Zabbix API 4 | 5 | ##### Compatibility 6 | - Tested with Zabbix 2.4 7 | - Tested with Zabbix 3.4 8 | - Tested with Powershell 5.0+ 9 | - Tested with Powershell Core 6.0+ 10 | 11 | ##### Based on: 12 | - [Zabbix]() by Benjamin RIOUAL 13 | - [ZabbixPosh Api]() by simsaull 14 | 15 | ##### Zabbix Docs: 16 | - [Zabbix API Libraries]() 17 | - [Zabbix 2.4 API documentation]() 18 | - [Zabbix 3.4 API documentation]() 19 | - [Zabbix 4.2 API documentation]() 20 | 21 | ### Warning: 22 | - Be careful. Especially with the mass delete and the mass update. 23 | - Bugs happen. Use on your own risk. 24 | 25 | ### Experimental: 26 | Get-ZabbixHostInventory 27 | - Get stats from inventories 28 | ```powershell 29 | Get-ZabbixHostInventory | ? os | group os -NoElement | sort count -desc 30 | Get-ZabbixHostInventory | ? os -match linux | select hostid,name,os,tag | ft -a 31 | Get-ZabbixHostInventory | ? location | group location -NoElement | sort count -desc 32 | ``` 33 | Set-ZabbixHostInventory 34 | - Mass population the hosts' inventories: 35 | ```powershell 36 | Example: input-inventory-mass-data.csv (two hosts) 37 | 38 | HostID,Type,TypeDetails,Name,Alias,OSName,OSFullName,OSShortName,SerialNumberA,SerialNumberB,Tag,AssetTag,MACAddressA,MACAddressB,Hardware,DetailedHardware,Software,SoftwareDetails,SoftwareApplicationA,SoftwareApplicationB,SoftwareApplicationC,SoftwareApplicationD,SoftwareApplicationE,ContactPerson,Location,LocationLatitude,LocationLongitude,Notes,Chassis,Model,HWArchitecture,Vendor,ContractNumber,InstallerName,DeploymentStatus,URLA,URLB,URLC,HostNetworks,HostSubnetMask,HostRouter,OOBIPAddress,OOBHostSubnetMask,OOBRouter,HWPurchaseDate,HWInstallationDate,HWMaintenanceExpiryDate,HWDecommissioningDate,SiteAddressA,SiteAddressB,SiteAddressC,SiteCity,SiteState,SiteCountry,SiteZIPCode,SiteRackLocation,SiteNotes,PrimaryPOCName,PrimaryEmail,PrimaryPOCPhoneA,PrimaryPOCPhoneB,PrimaryPOCMobileNumber,PrimaryPOCScreenName,PrimaryPOCnNotes,SecondaryPOCName,SecondaryPOCEmail,SecondaryPOCPhoneA,SecondaryPOCPhoneB,SecondaryPOCMobileNumber,SecondaryPOCScreenName,SecondaryPOCNotes 39 | 10000,Type,TypeDetails,Name,Alias,OSName,DetailedOSName,ShortOSName,SerialNumberA,SerialNumberBB,Tag,AssetTag,MACAddressA,MACAddressB,Hardware,DetailedHardware,Software,SoftwareDetails,SoftwareApplicationA,SoftwareApplicationB,SoftwareApplicationC,SoftwareApplicationD,SoftwareApplicationE,ContactPerson,Location,LocLat,LocLong,Notes,Chassis,Model,HWArchitecture,Vendor,ContractNumber,InstallerName,DeploymentStatus,URLA,URLB,URLC,HostNetworks,HostSubnetMask,HostRouter,OOBIPAddress,OOBHostSubnetMask,OOBRouter,HWPurchaseDate,HWInstallationDate,HWMaintenanceExpiryDate,HWDecommissioningDate,SiteAddressA,SiteAddressB,SiteAddressC,SiteCity,SiteState,SiteCountry,SiteZIPCode,SiteRackLocation,SiteNotes,PrimaryPOCName,PrimaryEmail,PrimaryPOCPhoneA,PrimaryPOCPhoneB,PrimaryPOCMobileNumber,PrimaryPOCScreenName,PrimaryPOCnNotes,SecondaryPOCName,SecondaryPOCEmail,SecondaryPOCPhoneA,SecondaryPOCPhoneB,SecondaryPOCMobileNumber,SecondaryPOCScreenName,SecondaryPOCNotes 40 | 10001,Type,TypeDetails,Name,Alias,OSName,DetailedOSName,ShortOSName,SerialNumberA,SerialNumberBB,Tag,AssetTag,MACAddressA,MACAddressB,Hardware,DetailedHardware,Software,SoftwareDetails,SoftwareApplicationA,SoftwareApplicationB,SoftwareApplicationC,SoftwareApplicationD,SoftwareApplicationE,ContactPerson,Location,LocLat,LocLong,Notes,Chassis,Model,HWArchitecture,Vendor,ContractNumber,InstallerName,DeploymentStatus,URLA,URLB,URLC,HostNetworks,HostSubnetMask,HostRouter,OOBIPAddress,OOBHostSubnetMask,OOBRouter,HWPurchaseDate,HWInstallationDate,HWMaintenanceExpiryDate,HWDecommissioningDate,SiteAddressA,SiteAddressB,SiteAddressC,SiteCity,SiteState,SiteCountry,SiteZIPCode,SiteRackLocation,SiteNotes,PrimaryPOCName,PrimaryEmail,PrimaryPOCPhoneA,PrimaryPOCPhoneB,PrimaryPOCMobileNumber,PrimaryPOCScreenName,PrimaryPOCnNotes,SecondaryPOCName,SecondaryPOCEmail,SecondaryPOCPhoneA,SecondaryPOCPhoneB,SecondaryPOCMobileNumber,SecondaryPOCScreenName,SecondaryPOCNotes 41 | 42 | Command: 43 | Import-csv input-inventory-mass-data.csv | %{$splatParams=@{}}{$splatParams=(("$_").trim('@{}').replace("; ","`r`n") | ConvertFrom-StringData); Set-ZabbixHostInventory @splatParams} 44 | ``` 45 | 46 | ### Installation from GitHub 47 | ```powershell 48 | cd $env:Userprofile\Documents\WindowsPowerShell\Modules\ 49 | git clone https://github.com/yubu/psbbix.git 50 | Import-Module psbbix 51 | ``` 52 | or 53 | ```powershell 54 | cd c:\temp 55 | git clone https://github.com/yubu/psbbix.git 56 | Import-Module c:\temp\psbbix\psbbix.psm1 57 | ``` 58 | ### Installation from Powershell Gallery 59 | Install-Module psbbix 60 | 61 | 64 | 65 | ### Getting Started 66 | ##### Use powershell help to get commands and examples 67 | ```powershell 68 | gcm -module psbbix 69 | help get-zabbixhost -ex 70 | ## if you hate a lot of empty lines within powershell examples, you can compress the white space: 71 | help get-zabbixhost -ex | out-string | remove-emptyLines 72 | ``` 73 | ##### Use Get-ZabbixHelp (alias gzh) to find examples fast, in high density format. Search pattern will be highlighted by yellow color (Thanks to David Mohundro's Find-String module). 74 | ```powershell 75 | Get-ZabbixHelp help 76 | gzh -list # List module functions 77 | gzh -alias # List module aliases 78 | gzh * # Get all examples 79 | gzh host set # Get (Zabbix)host related command with verb set == Set-ZabbixHost 80 | gzh hostgroup new # Get (Zabbix)hostgroup related command with verb new == New-ZabbixHostGroup 81 | gzh item -pattern "cassandra|entropy" 82 | gzh alert -pattern "example 4" 83 | gzh graph -p path 84 | ``` 85 | ##### Connect 86 | ```powershell 87 | connect-Zabbix 10.10.10.10 88 | connect-Zabbix 10.10.10.10 -noSSL 89 | ``` 90 | 91 | ##### Session parameters 92 | ```powershell 93 | @zabSessionParams should be used with almost every command 94 | ``` 95 | 96 | ##### Get-ZabbixHost 97 | ```powershell 98 | Get-ZabbixHost -HostName hostname 99 | Get-ZabbixHost -HostName HostName 100 | ## all inline parameters are case sensitive! (because of Linux/MySQL) 101 | ## two above commands will work for different hosts 102 | ``` 103 | ```powershell 104 | Get-ZabbixHost -hostname Host | Get-ZabbixHttpTest -ea silent | select httptestid,name,steps 105 | Get-ZabbixHost -hostname Host | Get-ZabbixHttpTest -ea silent | select -ExpandProperty steps | ft -a 106 | ``` 107 | ```powershell 108 | Get-ZabbixHost | ? name -match "host" 109 | ## not case sensitive (powershell way) 110 | Get-ZabbixHost | ? name -match "" | measure 111 | ## count hosts 112 | ``` 113 | 114 | ##### New-ZabbixHost 115 | ```powershell 116 | New-ZabbixHost -HostName NewHost -IP 10.20.10.10 -GroupID 8 -TemplateID "10081","10166" 117 | ## create new host 118 | New-ZabbixHost -HostName NewHost -IP 10.20.10.10 -GroupID 8 -TemplateID (Get-ZabbixHost | ? name -match "host").parentTemplates.templateid -status 1 119 | ## create new host, but disabled (-status 1) 120 | ``` 121 | ```powershell 122 | Import-Csv c:\new-servers.csv | %{New-ZabbixHost -HostName $_.Hostname -IP $_.IP -GroupID $_.GroupID -TemplateID $_.TemplateID -status $_.status} 123 | ## mass create new hosts 124 | ``` 125 | ```powershell 126 | Get-ZabbixHost | ? name -match SourceHost | New-ZabbixHost -HostName NewHost -IP 10.20.10.10 127 | ## clone host with single interface 128 | ``` 129 | ```powershell 130 | Get-ZabbixHost | ? name -match SourceHost | New-ZabbixHost -HostName NewHostName -IP 10.20.10.10 -TemplateID (Get-ZabbixHost | ? name -match "SourceHost").parentTemplates.templateid -Interfaces (Get-ZabbixHostInterface -HostID (Get-ZabbixHost -HostName SourceHost).hostid) -status 1 131 | Get-ZabbixHost | ? name -match NewHost | Get-ZabbixHostInterface | %{Set-ZabbixHostInterface -IP 10.20.10.10 -InterfaceID $_.interfaceid -Port $_.port -HostID $_.hostid} 132 | ## clone host with multiple interfaces, then update interfaces with new IP 133 | ``` 134 | 135 | ##### Set-ZabbixHost 136 | ```powershell 137 | Get-ZabbixHost | ? name -eq "hostName" | Set-ZabbixHost -status 1 138 | ## disable one host 139 | Get-ZabbixHost | ? name -match "hostName" | %{Set-ZabbixHost -status 1 -HostID $_.hostid -parentTemplates $_.parenttemplates} 140 | ## disable multiple hosts 141 | ``` 142 | > **Warning**: 143 | If host has multiple linked templates and then Set-ZabbixHost will be executed with single new template, ALL templates will be replaced by only ONE new template. 144 | ```powershell 145 | ## this will work: 146 | Get-ZabbixHost -HostName HostName | Set-ZabbixHost -TemplateID ExistingTemplateID,ExistingTemplateID,NewTemplateID 147 | ## and this: 148 | $templateID=(Get-ZabbixTemplate -HostID (Get-ZabbixHost | ? name -match hostname).hostid).templateid 149 | #Store existing templateIDs 150 | $templateID+=(Get-ZabbixTemplate | ? name -match "newTemplate").templateid 151 | #Add new templateIDs 152 | Get-ZabbixHost | ? name -match hosts | Set-ZabbixHost -TemplateID $templateID 153 | ``` 154 | 155 | 156 | 157 | ##### Remove-ZabbixHost 158 | ```powershell 159 | ##!! use carefully !!## 160 | Remove-ZabbixHost -HostID (Get-ZabbixHost -HostName ThisHostsRetired).hostid -WhatIf 161 | ## remove host(s) (case sensitive) (check only) 162 | Remove-ZabbixHost -HostID (Get-ZabbixHost -HostName ThisHostsRetired).hostid 163 | ## remove host(s) (case sensitive) 164 | Get-ZabbixHost | ? name -eq RetiredHost | Remove-ZabbixHost 165 | ## remove single host (case insensitive) 166 | Get-ZabbixHost | ? name -match "HostName-0[1-8]" | %{Remove-ZabbixHost -HostID $_.hostid} 167 | ## delete multiple hosts 168 | ``` 169 | 170 | ##### Get-ZabbixTemplate 171 | ```powershell 172 | Get-ZabbixTemplate | select name,hosts 173 | ``` 174 | 175 | ##### Get-ZabbixMaintenance 176 | ```powershell 177 | Get-ZabbixMaintenance | select maintenanceid,name 178 | (Get-ZabbixMaintenance -MaintenanceName "Maintenance").timeperiods 179 | Get-ZabbixMaintenance | select -Property @{n="MaintenanceName";e={$_.name}} -ExpandProperty timeperiods | ft -a 180 | ## Get maintenance and timeperiods 181 | Get-ZabbixMaintenance | select -Property @{n="MaintenanceName";e={$_.name}} -ExpandProperty timeperiods | select MaintenanceName,timeperiodid,timeperiod_type,@{n="start_date(UTC)";e={convertfrom-epoch $_.start_date}},@{n="period(Hours)";e={$_.period/3600}} | ft -a 182 | ## Get maintenance and timeperiods (Time in UTC) 183 | ``` 184 | ```powershell 185 | Get-ZabbixMaintenance | ? name -match "" | select Name,@{n="TimeperiodStart";e={(convertfrom-epoch $_.timeperiods.start_date).addhours(-5)}},@{n="Duration(hours)";e={$_.timeperiods.period/3600}} 186 | ## get all maintenances, display name, timeperiod (according UTC-5) and duration 187 | ``` 188 | 189 | ##### New-ZabbixMaintenance 190 | ```powershell 191 | New-ZabbixMaintenance -HostID (Get-ZabbixHost | ? name -match "hosts").hostid -MaintenanceName "NewMaintenance" -ActiveSince (convertTo-epoch ((get-date).addhours(0)).ToUniversalTime()) -ActiveTill (convertTo-epoch ((get-date).addhours(7)).ToUniversalTime()) -TimeperiodPeriod (4*3600) 192 | -ActiveSince (convertTo-epoch ((get-date).addhours(0)).ToUniversalTime()) == now 193 | -ActiveTill (convertTo-epoch ((get-date).addhours(7)).ToUniversalTime()) == now + 7 hours 194 | -TimeperiodPeriod (5*3600) == 5 hours 195 | ## Create new maintenance (time sent UTC, and will appear according Zabbix server) 196 | New-ZabbixMaintenance -HostID (Get-ZabbixHost | ? name -match otherhost).hostid -MaintenanceName NewMaintenanceName -MaintenanceDescription NewMaintenanceDescription -ActiveSince (convertTo-epoch (get-date -date "05/25/2015 07:05")) -ActiveTill (convertTo-epoch (get-date -date "05/25/2015 17:05")) -TimeperiodPeriod (7*3600) -TimeperiodStartDate (convertTo-epoch (get-date -date "05/25/2015 09:05") 197 | ## Create new, future maintenance (case sensitive) (time will be sent in UTC). Will be set on Zabbix server according it's local time. 198 | ``` 199 | 200 | ##### Remove-ZabbixMaintenance 201 | ```powershell 202 | Remove-ZabbixMaintenance -MaintenanceID "3","4" 203 | Get-ZabbixMaintenance | ? name -match "MaintenanceName" | Remove-ZabbixMaintenance -WhatIf 204 | ``` 205 | 206 | ##### Export-ZabbixConfig 207 | ```powershell 208 | Export-ZabbixConfig -HostID (Get-ZabbixHost | ? name -match host).hostid | sc c:\zabbix-hosts-export.xml 209 | Export-ZabbixConfig -TemplateID (Get-ZabbixTemplate | ? name -match "My template").templateid | sc c:\zabbix-templates-export.xml 210 | ``` 211 | 212 | ##### Get-ZabbixAlert 213 | ```powershell 214 | Get-ZabbixAlert | ? sendto -match Email | select @{n="Time(UTC-5)";e={(convertfrom-epoch $_.clock).addhours(-5)}},alertid,subject 215 | ## get alarms from last 3 hours (default params). Time display UTC-5 216 | Get-ZabbixAlert -TimeFrom (convertTo-epoch (get-date -date (((get-date).addhours(-5)).ToString())) -UTCOffset +0) -TimeTill (convertTo-epoch (get-date -date (((get-date).addhours(-4)).ToString())) -UTCOffset +0) | ? sendto -match Email | ? subject -match OK | select @{n="Time(UTC)";e={convertfrom-epoch $_.clock}},alertid,sendto,subject 217 | ## get alerts with custom timewindow of 1 hour. (-timeFrom, -timeTill) 218 | ``` 219 | ```powershell 220 | Get-ZabbixAlert -HostID (Get-ZabbixHost | ? name -match "Host|Other").hostid | ? sendto -match Email | select @{n="Time(UTC+3)";e={(convertfrom-epoch $_.clock).addhours(-5)}},alertid,subject 221 | ## works for multiple hosts. Get alerts for host from last 3 hours (default params). Display time in UTC -5 222 | ``` 223 | 224 | ##### Get-ZabbixUser 225 | ```powershell 226 | Get-ZabbixUser | select name,alias, attempt_ip, @{n="attempt_clock (UTC-5)"; e={((convertfrom-epoch $_.attempt_clock)).addhours(-5)}},@{n="usrgrps";e={$_.usrgrps.name}} 227 | ``` 228 | 229 | ##### Remove-ZabbixUser 230 | ```powershell 231 | Get-ZabbixUser | ? alias -eq "alias" | Remove-ZabbixUser 232 | ## delete one user 233 | Remove-ZabbixUser -UserID (Get-ZabbixUser | ? alias -match "alias").userid 234 | ## delete multiple users 235 | ``` 236 | 237 | ##### Set-ZabbixUser 238 | ```powershell 239 | Get-ZabbixUser | ? alias -match "alias" | Set-ZabbixUser -verbose -Name NewName -Surname NewSurname -rows_per_page 100 240 | ``` 241 | 242 | ##### New-ZabbixUser 243 | ```powershell 244 | Get-Zabbixuser | ? alias -match "User" | New-ZabbixUser -Name NewName -Surname NewSurname -Alias first.last -verbose -passwd "123456" 245 | ## clone user 246 | ``` 247 | 248 | ##### Get-ZabbixUserGroup 249 | ```powershell 250 | Get-ZabbixUserGroup | select usrgrpid,name 251 | (Get-ZabbixUserGroup | ? name -match administrators).users | select alias,users_status 252 | ``` 253 | 254 | ##### Get-ZabbixTrigger 255 | ```powershell 256 | Get-ZabbixTrigger -TemplateID (Get-ZabbixTemplate | ? name -match Template).templateid -ExpandDescription -ExpandExpression | ft -a status,description,expression 257 | ## get triggers by template 258 | Get-ZabbixHost -HostName HostName | Get-ZabbixTrigger -ea silent | ? status -match 0 | ft -a status,templateid,description,expression 259 | ## get triggers by host (case sensitive) 260 | ``` 261 | 262 | ##### Set-ZabbixTrigger 263 | ```powershell 264 | Get-ZabbixTrigger -TemplateID (Get-zabbixTemplate | ? name -match "Template JMX JVM Generic").templateid | ? description -match "uses suboptimal JIT compiler" | Set-ZabbixTrigger -status 1 265 | ## disable trigger 266 | ``` 267 | 268 | ##### Get-ZabbixAction 269 | ```powershell 270 | Get-ZabbixAction | select name 271 | Get-ZabbixAction | ? name -match action | select name,def_longdata,r_longdata 272 | ``` 273 | 274 | ##### Set-ZabbixAction 275 | ```powershell 276 | Get-ZabbixAction | ? name -match actionName | Set-ZabbixAction -status 1 277 | ## disable action 278 | ``` 279 | 280 | ##### Get-ZabbixHostInterface 281 | ```powershell 282 | Get-ZabbixHostInterface -HostID (Get-ZabbixHost -HostName ThisHost).hostid 283 | Get-ZabbixHost -HostName HostName | Get-ZabbixHostInterface 284 | ``` 285 | 286 | ##### Set-ZabbixHostInterface 287 | ```powershell 288 | Get-ZabbixHost | ? name -match host | Get-ZabbixHostInterface | %{Set-ZabbixHostInterface -IP 10.20.10.12 -InterfaceID $_.interfaceid -HostID $_.hostid -Port $_.port} 289 | ## Modify interface settings for the single host 290 | (1..100) | %{Get-ZabbixHost | ? name -match "host0$_" | Get-ZabbixHostInterface | ? port -match 31721 | Set-ZabbixHostInterface -main 1} 291 | ## Make interface default on all hosts 292 | ``` 293 | 294 | ##### New-ZabbixHostInterface 295 | ```powershell 296 | Get-ZabbixHost | ? name -match host | New-ZabbixHostInterface -IP 10.20.10.15 -port 31721 297 | ## Create new interface for the single host 298 | (1..100) | %{Get-ZabbixHost | ? name -match "host0$_" | New-ZabbixHostInterface -Port 31771 -type 4 -main 1 -ip (Get-ZabbixHost | ? name -match "host0$_").interfaces.ip[0]} 299 | ## Create new JMX connection and set it default 300 | ``` 301 | 302 | ##### Remove-ZabbixHostInterface 303 | ```powershell 304 | Get-ZabbixHost | ? name -match "host02" | Get-ZabbixHostInterface | ? port -Match 31721 | Remove-ZabbixHostInterface 305 | ## Remove interface on single host 306 | Remove-ZabbixHostInterface -interfaceid (Get-ZabbixHost | ? name -match "host02" | Get-ZabbixHostInterface).interfaceid 307 | ## Remove all interfaces from the host 308 | ``` 309 | 310 | ##### Get-ZabbixHttpTest 311 | ```powershell 312 | Get-ZabbixHttpTest | ? name -match httpTest | select httptestid,name 313 | Get-ZabbixHttpTest | ? name -like "test*Name" | ? {$_.hosts.host -match "Template name"}) | select name,@{e={$_.steps.url}},@{n='host';e={$_.hosts.host}} | sort host 314 | ``` 315 | 316 | ##### New-ZabbixHttpTest 317 | ```powershell 318 | New-ZabbixHttpTest -HttpTestName NewHttpTest -HttpTestStepURL "http://{HOST.CONN}:30555/health-check/do" -HttpTestStepRequired "version" -HostID (Get-ZabbixHost -HostName HostName).hostid 319 | ## create new http test 320 | Get-ZabbixTemplate | ? name -eq "Template Name" | Get-ZabbixHttpTest | ? name -match httpTestSource | New-ZabbixHttpTest -HttpTestName NewHttpName 321 | ## clone http test 322 | ``` 323 | 324 | ##### Set-ZabbixHttpTest 325 | ```powershell 326 | Get-ZabbixHttpTest -HttpTestName httpTest | Set-ZabbixHttpTest -status 1 327 | ## disable http test 328 | ``` 329 | 330 | ##### Remove-ZabbixHttpTest 331 | ```powershell 332 | Remove-ZabbixHttpTest -HttpTestID (Get-ZabbixTemplate | ? name -eq "Template Name" | Get-ZabbixHttpTest | ? name -match httpTests).httptestid 333 | ## delete http tests 334 | ``` -------------------------------------------------------------------------------- /epoch-time-convert.ps1: -------------------------------------------------------------------------------- 1 | Function convertFrom-epoch { 2 | <# 3 | .Synopsis 4 | Convert from epoch time to human 5 | .Description 6 | Convert from epoch time to human 7 | .Example 8 | convertFrom-epoch 1295113860 9 | .Example 10 | convertFrom-epoch 1295113860 | convertTo-epoch 11 | #> 12 | [CmdletBinding()] 13 | param ([Parameter(ValueFromPipeline=$true)]$epochdate) 14 | 15 | process { 16 | if (!$psboundparameters.count) {gh -ex $PSCmdlet.MyInvocation.MyCommand.Name | out-string | remove-emptylines; return} 17 | #[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($epochdate)) 18 | if (("$epochdate").length -gt 10 ) { 19 | # (Get-Date -Date "01/01/1970").AddMilliseconds($epochdate) 20 | if (("$epochdate").Contains('.')) { 21 | $seconds=("$epochdate").Split('.')[0] 22 | $millis=("$epochdate").Split('.')[1] 23 | $epochdate=$seconds+($millis[0..2] -join "") 24 | (Get-Date -Date "01/01/1970").AddMilliseconds($epochdate) 25 | } 26 | else {(Get-Date -Date "01/01/1970").AddMilliseconds($epochdate)} 27 | } 28 | else {(Get-Date -Date "01/01/1970").AddSeconds($epochdate)} 29 | } 30 | } 31 | 32 | Function convertTo-epoch { 33 | <# 34 | .Synopsis 35 | Convert time to epoch 36 | .Description 37 | Convert time to epoch 38 | .Example 39 | convertTo-epoch (get-date -date "05/24/2015 17:05") 40 | .Example 41 | convertTo-epoch (get-date -date "05/24/2015 17:05") | convertFrom-epoch 42 | .Example 43 | (get-date -date "05/24/2015 17:05") | convertTo-epoch 44 | .Example 45 | get-date | convertTo-epoch 46 | .Example 47 | convertTo-epoch (get-date).ToUniversalTime() 48 | .Example 49 | convertTo-epoch (get-date).ToUniversalTime() | convertFrom-epoch 50 | .Example 51 | convertTo-epoch ((get-date).AddHours(2) 52 | #> 53 | [CmdletBinding()] 54 | param ( 55 | [Parameter(ValueFromPipeline=$true)]$date 56 | ) 57 | 58 | if (!$psboundparameters.count) {help -ex convertTo-epoch | Out-String | Remove-EmptyLines; return} 59 | 60 | $date=$date -f "mm/dd/yyyy hh:mm" 61 | (New-TimeSpan -Start (Get-Date -Date "01/01/1970") -End $date).TotalSeconds 62 | } -------------------------------------------------------------------------------- /psbbix.psd1: -------------------------------------------------------------------------------- 1 | # Module manifest for module 'psbbix' 2 | # 3 | # Generated by: yubu 4 | # 5 | # Generated on: 9/12/2016 6 | # 7 | @{ 8 | 9 | # Script module or binary module file associated with this manifest. 10 | RootModule = 'psbbix.psm1' 11 | 12 | # Version number of this module. 13 | ModuleVersion = '0.2.1' 14 | 15 | # Supported PSEditions 16 | # CompatiblePSEditions = @() 17 | 18 | # ID used to uniquely identify this module 19 | GUID = '1e1dd1ef-dadc-4e19-9931-a838fb8a2bca' 20 | 21 | # Author of this module 22 | Author = 'yubu' 23 | 24 | # Company or vendor of this module 25 | CompanyName = 'Unknown' 26 | 27 | # Copyright statement for this module 28 | Copyright = '(c) 2019 yubu. All rights reserved.' 29 | 30 | # Description of the functionality provided by this module 31 | Description = 'Powershell Zabbix API' 32 | 33 | # Minimum version of the Windows PowerShell engine required by this module 34 | PowerShellVersion = '5.0' 35 | 36 | # Name of the Windows PowerShell host required by this module 37 | # PowerShellHostName = '' 38 | 39 | # Minimum version of the Windows PowerShell host required by this module 40 | # PowerShellHostVersion = '' 41 | 42 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 43 | # DotNetFrameworkVersion = '' 44 | 45 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 46 | # CLRVersion = '' 47 | 48 | # Processor architecture (None, X86, Amd64) required by this module 49 | # ProcessorArchitecture = '' 50 | 51 | # Modules that must be imported into the global environment prior to importing this module 52 | # RequiredModules = @() 53 | 54 | # Assemblies that must be loaded prior to importing this module 55 | # RequiredAssemblies = @() 56 | 57 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 58 | # ScriptsToProcess = @() 59 | 60 | # Type files (.ps1xml) to be loaded when importing this module 61 | # TypesToProcess = @() 62 | 63 | # Format files (.ps1xml) to be loaded when importing this module 64 | # FormatsToProcess = @() 65 | 66 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 67 | # NestedModules = @() 68 | 69 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. 70 | # FunctionsToExport = @() 71 | FunctionsToExport = '*' 72 | 73 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. 74 | # CmdletsToExport = @() 75 | CmdletsToExport = '*' 76 | 77 | # Variables to export from this module 78 | VariablesToExport = '*' 79 | 80 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. 81 | # AliasesToExport = @() 82 | AliasesToExport = '*' 83 | 84 | 85 | # DSC resources to export from this module 86 | # DscResourcesToExport = @() 87 | 88 | # List of all modules packaged with this module 89 | # ModuleList = @() 90 | 91 | # List of all files packaged with this module 92 | # FileList = @() 93 | 94 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. 95 | PrivateData = @{ 96 | 97 | PSData = @{ 98 | 99 | # Tags applied to this module. These help with module discovery in online galleries. 100 | Tags = @('zabbix','api') 101 | 102 | # A URL to the license for this module. 103 | # LicenseUri = '' 104 | 105 | # A URL to the main website for this project. 106 | ProjectUri = 'https://github.com/yubu/psbbix-zabbix-api' 107 | 108 | # A URL to an icon representing this module. 109 | # IconUri = '' 110 | 111 | # ReleaseNotes of this module 112 | ReleaseNotes = 'https://github.com/yubu/psbbix-zabbix-api/blob/master/CHANGELOG.md' 113 | 114 | # Prerelease information 115 | # Prerelease = '' 116 | 117 | } # End of PSData hashtable 118 | 119 | } # End of PrivateData hashtable 120 | 121 | # HelpInfo URI of this module 122 | # HelpInfoURI = 'https://github.com/yubu/psbbix-zabbix-api/blob/master/README.md' 123 | 124 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 125 | # DefaultCommandPrefix = '' 126 | 127 | } -------------------------------------------------------------------------------- /zabbix-db-size-calc.ps1: -------------------------------------------------------------------------------- 1 | #Zabbix DB Size calculator 2 | #https://www.zabbix.com/documentation/2.4/manual/installation/requirements#database_size 3 | function Get-ZabbixDBSize { 4 | param ($items, $history, $refreshRate=60, $trendsYears=3, $valuesPerSec) 5 | 6 | if (!$psboundparameters.count) { 7 | write-host "Example: Get-ZabbixDBSize -items 11284 -history 30 -trendsYears 3 -valuesPerSec 250" -f yellow 8 | write-host "Note1: The following values obtained from Zabbix Dashboard: Status of Zabbix: items, valuesPerSec" -f green 9 | write-host "Note2: The following values obtained from Templates: history and trends years" -f green 10 | return 11 | } 12 | 13 | #Zabbix configuration Fixed size. Normally 10MB or less. 14 | 15 | #For example, if we have 3000 items for monitoring with refresh rate of 60 seconds, the number of values per second is calculated as 3000/60 = 50. 16 | #It means that 50 new values are added to Zabbix database every second. 17 | if (!$valuesPerSec) {$valuesPerSec=$items/$refreshRate} 18 | #housekeeper settings for history: 19 | #If we would like to keep 30 days of history and we receive 50 values per second, total number of values will be around (30*24*3600)* 50 = 129.600.000, or about 130M of values. 20 | #days*(items/refresh rate)*24*3600*bytes 21 | #items : number of items 22 | #days : number of days to keep history 23 | #refresh rate : average refresh rate of items 24 | #bytes : number of bytes required to keep single value, depends on database engine, normally 50 bytes. 25 | $totalValues=($history*24*3600)*$valuesPerSec 26 | #Depending on the database engine used, type of received values (floats, integers, strings, log files, etc), the disk space for keeping a single value may vary from 40 bytes to hundreds of bytes. 27 | #Normally it is around 50 bytes per value. In our case, it means that 130M of values will require 130M * 50 bytes = 6.5GB of disk space. 28 | $historyDiskSpaceGB=$totalValues*50/1000000000 29 | $historyDiskSpaceMB=$totalValues*50/1000000 30 | #Housekeeper setting for trends: 31 | #Zabbix keeps a 1-hour max/min/avg/count set of values for each item in the table trends. The data is used for trending and long period graphs. The one hour period can not be customized. 32 | #Zabbix database, depending on database type, requires about 128 bytes per each total. Suppose we would like to keep trend data for 5 years. Values for 3000 items will require 3000*24*365* 128 = 3.4GB per year, or 16.8GB for 5 years. 33 | #days*(items/3600)*24*3600*bytes 34 | #items : number of items 35 | #days : number of days to keep history 36 | #bytes : number of bytes required to keep single trend, depends on database engine, normally 128 bytes. 37 | $trendsDiskSpaceGB=$items*24*365*$trendsYears*128/1000000000 38 | $trendsDiskSpaceMB=$items*24*365*$trendsYears*128/1000000 39 | #Housekeeper settings for events 40 | #Each Zabbix event requires approximately 130 bytes of disk space. It is hard to estimate the number of events generated by Zabbix daily. In the worst case scenario, we may assume that Zabbix generates one event per second. 41 | #It means that if we want to keep 3 years of events, this would require 3*365*24*3600* 130 = 12.3GB 42 | #days*events*24*3600*bytes 43 | #events : number of event per second. One (1) event per second in worst case scenario. 44 | #days : number of days to keep history 45 | #bytes : number of bytes required to keep single trend, depends on database engine, normally 130 bytes 46 | $eventsDiskSpaceGB=3*365*24*3600*130/1000000000 47 | $eventsDiskSpaceMB=3*365*24*3600*130/1000000 48 | 49 | $totalDBSizeGB=$historyDiskSpaceGB+$trendsDiskSpaceGB+$eventsDiskSpaceGB+0.01 50 | $totalDBSizeMB=$historyDiskSpaceMB+$trendsDiskSpaceMB+$eventsDiskSpaceMB+10 51 | 52 | write-host "Zabbix projected DBSize in GB = $("{0:N2}" -f $totalDBSizeGB)" -f cyan 53 | write-host "Zabbix projected DBSize in MB = $("{0:N2}" -f $totalDBSizeMB)" -f cyan 54 | } --------------------------------------------------------------------------------