lework 4 years ago
parent
commit
61400a43ae
  1. 119
      powershell/exchange/Manage-GroupManagementRole.ps1
  2. 467
      powershell/exchange/Microsoft-Welcome.html
  3. 52
      powershell/exchange/WelcomeMSG.ps1
  4. 8
      python/supervisor_healthCheck.py
  5. 7
      shell/ip.sh
  6. 34
      shell/k8s/docker-registry-gc.sh
  7. 16
      shell/k8s/tools.sh

119
powershell/exchange/Manage-GroupManagementRole.ps1

@ -0,0 +1,119 @@ @@ -0,0 +1,119 @@
# Script for creating a Role that can manage distributions groups but can't create new ones
#
#################################################################################
#
# The sample scripts are not supported under any Microsoft standard support
# program or service. The sample scripts are provided AS IS without warranty
# of any kind. Microsoft further disclaims all implied warranties including, without
# limitation, any implied warranties of merchantability or of fitness for a particular
# purpose. The entire risk arising out of the use or performance of the sample scripts
# and documentation remains with you. In no event shall Microsoft, its authors, or
# anyone else involved in the creation, production, or delivery of the scripts be liable
# for any damages whatsoever (including, without limitation, damages for loss of business
# profits, business interruption, loss of business information, or other pecuniary loss)
# arising out of the use of or inability to use the sample scripts or documentation,
# even if Microsoft has been advised of the possibility of such damages
#
#################################################################################
#
# Written by Matthew Byrd
# Matbyrd@microsoft.com
# Last Updated 10.15.09
# Parameter to get a different name than default for the new Role
Param([string]$name="MyDistributionGroupsManagement",[string]$policy="Default Role Assignment Policy",[switch]$creategroup,[switch]$removegroup)
# Help Function
Function Show-Help {
"
This script is will create or manage a management role designed to allow users to modify groups that they already own
but not create or remove any new distribution groups.
Switches:
-name Name of the managment role you want to create or modify
Defaults to: `"MyDistributionGroupsManagmenet`"
-policy Name of the Role Policy you want to assign the role to
Defaults to: `"Default Role Assignement Policy`"
-creategroup Adds or Removes the ability of the Role to Create DLs
-removegroup Adds or Removes the ability of the Role to Remove DLs
Examples:
--------------------------------------------
This will Use the default names and Policy and will create a role that cannot
Create or remove groups but can still modify them. If the role already exists
It will modify it by removing or adding the abiltity to create and remove groups
based on the current state.
Manage-GroupManagementRole -CreateGroup -RemoveGroup
"
}
# Function to modify a role by removing or adding Role Entries
# If no action is passed we assume remove
# $roleentry should be in the form Role\Roleentry e.g. MyRole\New-DistributionGroup
Function ModifyRole {
Param($roleenty,$action)
Switch ($action){
Add {Add-ManagementRoleEntry $roleenty -confirm:$false}
Remove {Remove-ManagementRoleEntry $roleenty -confirm:$false}
Default {Remove-ManagementRoleEntry $roleenty -confirm:$false}
}
}
If (($creategroup -eq $false) -and ($removegroup -eq $false)){
Show-Help
exit
}
# Test if we have a role that already has that name
If (([bool](Get-Managementrole $name -erroraction Silentlycontinue)) -eq $true){
Write-Warning "Found a Role with Name: $name"
Write-Warning "Trying to Modify Existing Role"
}
Else {
# Create the new Management Role
Write-Host "Creating Managmenet Role $name"
New-ManagementRole -name $name -parent MyDistributionGroups
}
# Determine if we have the New and Remove Role Entries on the Role Already
$create = [bool](Get-managementroleentry $name\New-DistributionGroup -erroraction Silentlycontinue)
$remove = [bool](Get-managementroleentry $name\Remove-DistributionGroup -erroraction Silentlycontinue)
# If we have the switch CreateGroup add or remove the RoleEntry for New-DistributionGroup
If ($creategroup -eq $true){
If ($create -eq $true){ModifyRole $name\New-DistributionGroup Remove;Write-Host "Removing ability to create distribution Groups from $name"}
elseif ($create -eq $false) {ModifyRole $name\New-DistributionGroup Add;Write-Host "Adding ability to create distribution Groups to $name"}
}
# If we have the switch RemoveGroup add or remove the RoleEntry for New-DistributionGroup
If ($removegroup -eq $true){
If ($remove -eq $true){ModifyRole $name\Remove-DistributionGroup Remove;Write-Host "Removing ability to create distribution Groups from $name"}
elseif ($remove -eq $false) {ModifyRole $name\Remove-DistributionGroup Add;Write-Host "Adding ability to create distribution Groups to $name"}
}
# Test if we have the assignment for the Role and Policy
# If we do ... write a warning
# If not create a new assignment
If (([bool](get-managementroleassignment $name-$policy -erroraction SilentlyContinue)) -eq $true){
Write-Warning "Found Existing Role Assignment: $name-$policy"
Write-Warning "Making no modifications to Role Assignments"
}
Else {
# Assign the Role to the Role Policy
Write-Host "Creating Managmenet Role Assignment $name-$policy"
New-ManagementRoleAssignment -name ($name + "-" + $policy) -role $name -policy $policy
}

467
powershell/exchange/Microsoft-Welcome.html

@ -0,0 +1,467 @@ @@ -0,0 +1,467 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Single Article</title>
</head>
<body yahoo bgcolor="#ffffff">
<table width="100%" bgcolor="#ffffff" border="0" cellpadding="10" cellspacing="0">
<tr>
<td>
<!--[if (gte mso 9)|(IE)]>
<table width="600" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<![endif]-->
<table bgcolor="#ffffff" class="content" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateContainer">
<tr>
<td valign="top" class="bodyContent" mc:edit="body_content_01">
<p>Hi and Welcome to Microsoft!</p>
<h1><strong>We are happy you have joined our company</strong></h1>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="50%" id="templateContainerImageFull" style="min-height:15px;">
<tr>
<td width="1">
<img src="http://c0185784a2b233b0db9b-d0e5e4adc266f8aacd2ff78abb166d77.r51.cf2.rackcdn.com/blank.png" style="width: 1px; display:block; margin:0; padding:0; border:0;"/>
</td>
<td valign="top" class="bodyContentImageFull" mc:edit="body_content_01">
<p style="text-align:center;margin:0;padding:0;float:right;">
<img src="http://1gew6o3qn6vx9kp3s42ge0y1-wpengine.netdna-ssl.com/wp-content/uploads/2012/08/1731.0841_5F00_Microsoft20Logo_5F00_1324B2E1.png" style="display:block; margin:0; padding:0; border:0;" />
</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="top">
<!-- BEGIN BODY // -->
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateContainerMiddle" class="brdBottomPadd">
<tr>
<td valign="top" class="bodyContent" mc:edit="body_content">
<h2><strong>Here is the most useful web site you can get</strong></h2>
<p>Enjoy!</p>
<a class="blue-btn" href="https://medium.com/@tkolber"><strong>Read now</strong></a>
</td>
</tr>
</table>
<!-- // END BODY -->
</td>
</tr>
<tr>
<td align="center" valign="top">
</td>
</tr>
<tr>
<td align="center" valign="top" id="bodyCellFooter" class="unSubContent">
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="templateContainerFooter">
<tr>
<td valign="top" width="100%" mc:edit="footer_unsubscribe">
<p style="text-align:center;">
<img src="http://c0185784a2b233b0db9b-d0e5e4adc266f8aacd2ff78abb166d77.r51.cf2.rackcdn.com/templates/cog-03.jpg" style="margin:0 auto 0 auto;display:inline-block;" />
</p>
<h6 style="text-align:center;margin-top: 9px;">Microsoft Israel LTD</h6>
<h6 style="text-align:center;">2&#8203; Hapnina&#8203; Street&#8203;</h6>
<h6 style="text-align:center;">Raanana,&#8203; IL&#8203; 972-762-5400&#8203;</h6>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</table>
<style type="text/css">
/* /\/\/\/\/\/\/\/\/ CLIENT-SPECIFIC STYLES /\/\/\/\/\/\/\/\/ */
#outlook a{padding:0;} /* Force Outlook to provide a "view in browser" message */
.ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;} /* Force Hotmail to display normal line spacing */
body, table, td, p, a, li, blockquote{-webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;} /* Prevent WebKit and Windows mobile changing default text sizes */
table, td{mso-table-lspace:0pt; mso-table-rspace:0pt;} /* Remove spacing between tables in Outlook 2007 and up */
td ul li {
font-size: 16px;
}
/* /\/\/\/\/\/\/\/\/ RESET STYLES /\/\/\/\/\/\/\/\/ */
body{margin:0; padding:0;}
img{
max-width:100%;
border:0;
line-height:100%;
outline:none;
text-decoration:none;
}
table{border-collapse:collapse !important;}
.content {width: 100%; max-width: 600px;}
.content img { height: auto; min-height: 1px; }
#bodyTable{margin:0; padding:0; width:100% !important;}
#bodyCell{margin:0; padding:0;}
#bodyCellFooter{margin:0; padding:0; width:100% !important;padding-top:39px;padding-bottom:15px;}
body {margin: 0; padding: 0; min-width: 100%!important;}
#templateContainerHeader{
font-size: 14px;
padding-top:2.429em;
padding-bottom:0.929em;
}
#templateContainerImageFull { border-left:1px solid #e2e2e2; border-right:1px solid #e2e2e2; }
#templateContainerFootBrd{
border-bottom:1px solid #e2e2e2;
border-left:1px solid #e2e2e2;
border-right:1px solid #e2e2e2;
border-radius: 0 0 4px 4px;
background-clip: padding-box;
border-spacing: 0;
height: 10px;
width:100% !important;
}
#templateContainer{
border-top:1px solid #e2e2e2;
border-left:1px solid #e2e2e2;
border-right:1px solid #e2e2e2;
border-radius: 4px 4px 0 0 ;
background-clip: padding-box;
border-spacing: 0;
}
#templateContainerMiddle {
border-left:1px solid #e2e2e2;
border-right:1px solid #e2e2e2;
}
#templateContainerMiddleBtm {
border-left:1px solid #e2e2e2;
border-right:1px solid #e2e2e2;
border-bottom:1px solid #e2e2e2;
border-radius: 0 0 4px 4px;
background-clip: padding-box;
border-spacing: 0;
}
/**
* @tab Page
* @section heading 1
* @tip Set the styling for all first-level headings in your emails. These should be the largest of your headings.
* @style heading 1
*/
h1{
color:#2e2e2e;
display:block;
font-family:Helvetica;
font-size:26px;
line-height:1.385em;
font-style:normal;
font-weight:normal;
letter-spacing:normal;
margin-top:0;
margin-right:0;
margin-bottom:15px;
margin-left:0;
text-align:left;
}
/**
* @tab Page
* @section heading 2
* @tip Set the styling for all second-level headings in your emails.
* @style heading 2
*/
h2{
color:#2e2e2e;
display:block;
font-family:Helvetica;
font-size:22px;
line-height:1.455em;
font-style:normal;
font-weight:normal;
letter-spacing:normal;
margin-top:0;
margin-right:0;
margin-bottom:15px;
margin-left:0;
text-align:left;
}
/**
* @tab Page
* @section heading 3
* @tip Set the styling for all third-level headings in your emails.
* @style heading 3
*/
h3{
color:#545454;
display:block;
font-family:Helvetica;
font-size:18px;
line-height:1.444em;
font-style:normal;
font-weight:normal;
letter-spacing:normal;
margin-top:0;
margin-right:0;
margin-bottom:15px;
margin-left:0;
text-align:left;
}
/**
* @tab Page
* @section heading 4
* @tip Set the styling for all fourth-level headings in your emails. These should be the smallest of your headings.
* @style heading 4
*/
h4{
color:#545454;
display:block;
font-family:Helvetica;
font-size:14px;
line-height:1.571em;
font-style:normal;
font-weight:normal;
letter-spacing:normal;
margin-top:0;
margin-right:0;
margin-bottom:15px;
margin-left:0;
text-align:left;
}
h5{
color:#545454;
display:block;
font-family:Helvetica;
font-size:13px;
line-height:1.538em;
font-style:normal;
font-weight:normal;
letter-spacing:normal;
margin-top:0;
margin-right:0;
margin-bottom:15px;
margin-left:0;
text-align:left;
}
h6{
color:#545454;
display:block;
font-family:Helvetica;
font-size:12px;
line-height:2.000em;
font-style:normal;
font-weight:normal;
letter-spacing:normal;
margin-top:0;
margin-right:0;
margin-bottom:15px;
margin-left:0;
text-align:left;
}
p {
color:#545454;
display:block;
font-family:Helvetica;
font-size:16px;
line-height:1.500em;
font-style:normal;
font-weight:normal;
letter-spacing:normal;
margin-top:0;
margin-right:0;
margin-bottom:15px;
margin-left:0;
text-align:left;
}
.unSubContent a:visited { color: #a1a1a1; text-decoration:underline; font-weight:normal;}
.unSubContent a:focus { color: #a1a1a1; text-decoration:underline; font-weight:normal;}
.unSubContent a:hover { color: #a1a1a1; text-decoration:underline; font-weight:normal;}
.unSubContent a:link { color: #a1a1a1 ; text-decoration:underline; font-weight:normal;}
.unSubContent a .yshortcuts { color: #a1a1a1 ; text-decoration:underline; font-weight:normal;}
.unSubContent h6 {
color: #a1a1a1;
font-size: 12px;
line-height: 1.5em;
margin-bottom: 0;
}
.bodyContent{
color:#505050;
font-family:Helvetica;
font-size:14px;
line-height:150%;
padding-top:3.143em;
padding-right:3.5em;
padding-left:3.5em;
padding-bottom:0.714em;
text-align:left;
}
.bodyContentImage {
color:#505050;
font-family:Helvetica;
font-size:14px;
line-height:150%;
padding-top:2em;
padding-right:3.571em;
padding-left:3.571em;
padding-bottom:2em;
text-align:left;
}
.bodyContentImage h4 {
color: #4E4E4E;
font-size: 13px;
line-height: 1.154em;
font-weight:normal;
margin-bottom: 0;
}
.bodyContentImage h5 {
color: #828282;
font-size: 12px;
line-height: 1.667em;
margin-bottom: 0;
}
/**
* @tab Body
* @section body link
* @tip Set the styling for your email's main content links. Choose a color that helps them stand out from your text.
*/
a:visited { color: #3386e4; text-decoration:none;}
a:focus { color: #3386e4; text-decoration:none;}
a:hover { color: #3386e4; text-decoration:none;}
a:link { color: #3386e4 ; text-decoration:none;}
a .yshortcuts { color: #3386e4 ; text-decoration:none;}
.bodyContent img{
height:auto;
max-width:498px;
}
.footerContent{
color:#808080;
font-family:Helvetica;
font-size:10px;
line-height:150%;
padding-top:2.000em;
padding-right:2.000em;
padding-bottom:2.000em;
padding-left:2.000em;
text-align:left;
}
/**
* @tab Footer
* @section footer link
* @tip Set the styling for your email's footer links. Choose a color that helps them stand out from your text.
*/
.footerContent a:link, .footerContent a:visited, /* Yahoo! Mail Override */ .footerContent a .yshortcuts, .footerContent a span /* Yahoo! Mail Override */{
color:#606060;
font-weight:normal;
text-decoration:underline;
}
/**
* @tab Footer
* @section footer link
* @tip Set the styling for your email's footer links. Choose a color that helps them stand out from your text.
*/
.bodyContentImageFull p { font-size:0 !important; margin-bottom: 0 !important; }
.brdBottomPadd { border-bottom: 1px solid #f0f0f0; }
.brdBottomPadd .bodyContent { padding-bottom: 2.286em; }
a.blue-btn {
background: #5098ea;
display: inline-block;
color: #FFFFFF;
border-top:10px solid #5098ea;
border-bottom:10px solid #5098ea;
border-left:20px solid #5098ea;
border-right:20px solid #5098ea;
text-decoration: none;
font-size: 14px;
margin-top: 1.0em;
border-radius: 3px 3px 3px 3px;
background-clip: padding-box;
}
@media only screen and (max-width: 550px), screen and (max-device-width: 550px) {
body[yahoo] .hide {display: none!important;}
body[yahoo] .buttonwrapper {background-color: transparent!important;}
body[yahoo] .button {padding: 0px!important;}
body[yahoo] .button a {background-color: #e05443; padding: 15px 15px 13px!important;}
body[yahoo] .unsubscribe { font-size: 14px; display: block; margin-top: 0.714em; padding: 10px 50px; background: #2f3942; border-radius: 5px; text-decoration: none!important;}
}
/*@media only screen and (min-device-width: 601px) {
.content {width: 600px !important;}
}*/
@media only screen and (max-width: 480px) {
h1 {
font-size:34px !important;
}
h2{
font-size:30px !important;
}
h3{
font-size:24px !important;
}
h4{
font-size:18px !important;
}
h5{
font-size:16px !important;
}
h6{
font-size:14px !important;
}
p {
font-size: 18px !important;
}
.brdBottomPadd .bodyContent { padding-bottom: 2.286em !important; }
.bodyContent {
padding: 6% 5% 1% 6% !important;
}
.bodyContent img {
max-width: 100% !important;
}
.bodyContentImage {
padding: 3% 6% 6% 6% !important;
}
.bodyContentImage img {
max-width: 100% !important;
}
.bodyContentImage h4 {
font-size: 16px !important;
}
.bodyContentImage h5 {
font-size: 15px !important;
margin-top:0;
}
}
.ii a[href] {color: inherit !important;}
span > a, span > a[href] {color: inherit !important;}
a > span, .ii a[href] > span {text-decoration: inherit !important;}
</style>
</body>
</html>

52
powershell/exchange/WelcomeMSG.ps1

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
#Disclaimer:
#The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
#Parameters to change:
# 1. Location of the HTML file:
$welcomemsg="C:\scripts\Microsoft-Welcome.html"
# 2. Email address of the welcome email sender (any email address in your domain):
$Sender="SYSTEM@msft.net"
# 3. Subject of the welcome email message:
$Sub="Welcome to MSFT"
# 4. hr represents the amount of time in hours the script checks for new mailboxes.
# The default is 1 hour back, means that it checks which mailboxes were created in the last hour.
$hr="1"
#End Parameters
$dom=$sender.Split("@") | Select-Object -Last 1
$StartDate = (Get-Date).AddHours(-$hr)
$srvsmtp=Get-PSSession | ? {$_.State -eq "Opened"} | select -First 1 | select ComputerName
$srvsend=$srvsmtp.computername
$EndDate = Get-Date
$EndDateMSG=(Get-Date).AddDays(+1)
$body = Get-Content $welcomemsg -Raw
$mbx=Search-AdminAuditLog -StartDate $StartDate -EndDate $EndDate -ResultSize 1000 -Cmdlets New-Mailbox,Enable-Mailbox |select ObjectModified
If ($mbx -ne $null)
{
$usrname=$mbx.ObjectModified
$usrname | % $username {"$_"| Get-User | Select Name} | out-null
$Onlyname=$usrname | % $username {"$_"| Get-User | Select Name}
$usr=$Onlyname.name
ForEach ($_ in $usr)
{
$sent=Get-MailboxServer -WarningAction SilentlyContinue | Get-MessageTrackingLog -ResultSize 1000 -Recipients "$_@$dom" -Sender "$Sender" -Start $StartDate -End $EndDateMSG -ErrorAction SilentlyContinue | ? {$_.EventId -eq "DELIVER"} | sort-object -property subject | Select-Object | ? {$_.MessageSubject -eq "$sub"}
if ($sent -eq $null)
{
Send-MailMessage -From "$Sender" -To "$_@$dom" -Subject "$Sub" -Body $body -BodyAsHtml -SmtpServer "$srvsend" -Port 25 -UseSsl:$false
Write-Host -ForegroundColor Green "A Messages sent to $_"
}
Else
{
Write-Host -ForegroundColor DarkCyan "A Messages was already sent to $_"
}
}
}
Else
{
Write-Host -ForegroundColor Red "There are no new mailboxes"
Exit
}

8
python/supervisor_healthCheck.py

@ -892,7 +892,7 @@ cat1: # supervisor中配置的program名称 @@ -892,7 +892,7 @@ cat1: # supervisor中配置的program名称
initialDelaySeconds: 10 # 首次检查等待的时间(以秒为单位), 默认: 1
failureThreshold: 3 # 检查成功后,最少连续检查失败多少次才被认定为失败, 默认: 3
successThreshold: 2 # 失败后检查成功的最小连续成功次数, 默认:1
action: restart,email # 触发的动作: restart,exec,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
action: restart,email # 触发的动作: restart,exec,kill,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
execCmd: command # action exec 的执行命令
sendResolved: True # 是否发送恢复通知,仅用作于email,wechat. 默认: False
@ -906,7 +906,7 @@ cat2: # supervisor中配置的program名称 @@ -906,7 +906,7 @@ cat2: # supervisor中配置的program名称
initialDelaySeconds: 10 # 首次检查等待的时间(以秒为单位), 默认: 1
failureThreshold: 3 # 检查成功后,最少连续检查失败多少次才被认定为失败, 默认: 3
successThreshold: 2 # 失败后检查成功的最小连续成功次数, 默认:1
action: restart,email # 触发的动作: restart,exec,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
action: restart,email # 触发的动作: restart,exec,kill,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
execCmd: command # action exec 的执行命令
sendResolved: True # 是否发送恢复通知,仅用作于email,wechat. 默认: False
@ -926,7 +926,7 @@ cat3: @@ -926,7 +926,7 @@ cat3:
timeoutSeconds: 5 # 检查超时的秒数, 默认: 3
failureThreshold: 3 # 检查成功后,最少连续检查失败多少次才被认定为失败, 默认: 3
successThreshold: 2 # 失败后检查成功的最小连续成功次数, 默认:1
action: restart,email # 触发的动作: restart,exec,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
action: restart,email # 触发的动作: restart,exec,kill,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
execCmd: command # action exec 的执行命令
sendResolved: True # 是否发送恢复通知,仅用作于email,wechat. 默认: False
@ -940,7 +940,7 @@ cat4: @@ -940,7 +940,7 @@ cat4:
timeoutSeconds: 5 # 检查超时的秒数, 默认: 3
failureThreshold: 3 # 检查成功后,最少连续检查失败多少次才被认定为失败, 默认: 3
successThreshold: 2 # 失败后检查成功的最小连续成功次数, 默认:1
action: restart,email # 触发的动作: restart,exec,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
action: restart,email # 触发的动作: restart,exec,kill,email,wechat (restart和exec互斥,同时设置时restart生效) 默认: restart
execCmd: command # action exec 的执行命令
sendResolved: True # 是否发送恢复通知,仅用作于email,wechat. 默认: False
"""

7
shell/ip.sh

@ -1,6 +1,13 @@ @@ -1,6 +1,13 @@
#!/bin/bash
get_ip_from_doh() {
local domain=${1:-www.baidu.com}
local dohs=(doh.defaultroutes.de dns.hostux.net uncensored.lux1.dns.nixnet.xyz dns.rubyfish.cn dns.alidns.com doh.centraleu.pi-dns.com doh.dns.sb doh-fi.blahdns.com fi.doh.dns.snopyta.org dns.flatuslifir.is doh.li dns.digitale-gesellschaft.ch)
ip=$(curl -4fsSLkA- -m200 "https://${dohs[$((RANDOM%10))]}/dns-query?name=${domain}" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" |tr ' ' '\n'|grep -Ev [.]0|sort -uR|head -1)
echo "${domain}: ${ip}"
}
get_addr () {
local if_name=$1
local uri_template=$2

34
shell/k8s/docker-registry-gc.sh

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
#!/bin/bash
v2=$1
v2=${v2:="/var/lib/registry/docker/registry/v2"}
all_blobs=/tmp/all_blobs.list
cd ${v2}
: > ${all_blobs}
# delete unlink blob's link file in _layers
for link in $(find repositories -type f -name "link" | grep -E "_layers\/sha256\/.*"); do
link_sha256=$(echo ${link} | grep -Eo "_layers\/sha256\/.*" | sed 's/_layers\/sha256\///g;s/\/link//g')
link_short=${link:0:2}
link_dir=$(echo ${link} | sed 's/\/link//')
data_file=blobs/sha256/${link_short}/${link}
if [[ ! -d ${data_file} ]]; then echo "Del link: ${link_dir}"; rm -rf ${link_dir}; fi
done
#marking all the blob by all images manifest
for tag in $(find repositories -name "link" | grep current); do
link=$(cat ${tag} | cut -c8-71)
mfs=blobs/sha256/${link:0:2}/${link}/data
echo ${link} >> ${all_blobs}
grep -Eo "\b[a-f0-9]{64}\b" ${mfs} | sort -n | uniq | cut -c1-12 >> ${all_blobs}
done
#delete blob if the blob doesn't exist in all_blobs.list
for blob in $(find blobs -name "data" | cut -d "/" -f4); do
if ! grep ${blob} ${all_blobs}; then
echo "Del blob: blobs/sha256/${blob:0:2}/${blob}"
rm -rf blobs/sha256/${blob:0:2}/${blob}
fi
done

16
shell/k8s/tools.sh

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
function e() {
# 快速进入容器命名空间
# exp: e POD_NAME NAMESPACE
set -eu
pod_name=${1}
ns=${2-"default"}
host_ip=$(kubectl -n $ns get pod $pod_name -o jsonpath='{.status.hostIP}')
container_id=$(kubectl -n $ns describe pod $pod_name | grep -A10 "^Containers:" | grep -Eo 'docker://.*$' | head -n 1 | sed 's/docker:\/\/\(.*\)$/\1/')
container_pid=$(docker inspect -f {{.State.Pid}} $container_id)
cmd="nsenter -n --target $container_pid"
echo "entering pod netns for [${host_ip}] $ns/$pod_name"
echo $cmd
$cmd
}
Loading…
Cancel
Save