-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Automattic/fix/ignore-for-jetpack-requests
Don't send 503 on requests coming from Jetpack
- Loading branch information
Showing
4 changed files
with
30 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
<?php | ||
|
||
/** | ||
* Prevent the maintenance_mode plugin returning a 503 HTTP status to Nagios. | ||
* Prevent the Maintenance Mode plugin returning a 503 HTTP status to Nagios and Jetpack. | ||
* | ||
* Maintenance_mode sets a 503 header on page requests if maintenance_mode is enabled and this leads to Nagios | ||
* reporting lots of server errors for sites that are just in maintenance_mode. This function sets the filter | ||
* response that maintenance_mode uses to determine if it shoudl set teh 503 status header or not. | ||
* Maintenance Mode sets a 503 header on page requests if Maintenance Mode is enabled and this leads to Nagios | ||
* reporting lots of server errors and Jetpack not being able to verify connection status for sites that are just in maintenance_mode. This function sets the filter | ||
* response that Maintenance Mode uses to determine if it should set the 503 status header or not. | ||
* | ||
* @return bool Should maintenance_mode set a 503 header | ||
* @return bool Should Maintenance Mode set a 503 header | ||
*/ | ||
function wpcom_vip_maintenance_mode_do_not_respond_503_for_nagios( $should_set_503 ) { | ||
function wpcom_vip_maintenance_mode_do_not_respond_503_for_services( $should_set_503 ): bool { | ||
$user_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; | ||
|
||
// The request comes from Nagios so deny the 503 header being set. | ||
// Desktop checks use something like `check_http/v2.2.1 (nagios-plugins 2.2.1)`. | ||
// Mobile checks use `iphone`. | ||
if ( false !== strpos( $user_agent, 'check_http' ) || 'iphone' === $user_agent ) { | ||
// Utilize helper function vip_is_jetpack_request if available | ||
if ( false !== strpos( $user_agent, 'check_http' ) || 'iphone' === $user_agent || ( function_exists( 'vip_is_jetpack_request' ) && vip_is_jetpack_request() ) ) { | ||
return false; | ||
} | ||
|
||
return $should_set_503; | ||
} | ||
|
||
add_filter( 'vip_maintenance_mode_respond_503', 'wpcom_vip_maintenance_mode_do_not_respond_503_for_nagios', 30 ); | ||
add_filter( 'vip_maintenance_mode_respond_503', 'wpcom_vip_maintenance_mode_do_not_respond_503_for_services', 30 ); |