mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	nagios: Switch check_user_zephyr_mirror_liveness to run via cron.
This check loads Django, and as such must be run as the zulip user. Repeat the same pattern used elsewhere in nagios, of writing a state file, which is read by `check_cron_file`.
This commit is contained in:
		
				
					committed by
					
						
						Alex Vandiver
					
				
			
			
				
	
			
			
			
						parent
						
							41deef40cf
						
					
				
				
					commit
					8bc26aab08
				
			@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					SHELL=/bin/bash
 | 
				
			||||||
 | 
					PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 | 
				
			||||||
 | 
					USER=zulip
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* * * * * zulip /usr/lib/nagios/plugins/zulip_zephyr_mirror/check_user_zephyr_mirror_liveness >/dev/null
 | 
				
			||||||
@@ -72,7 +72,7 @@ define command{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
define command{
 | 
					define command{
 | 
				
			||||||
        command_name    check_user_zephyr_mirror_liveness
 | 
					        command_name    check_user_zephyr_mirror_liveness
 | 
				
			||||||
        command_line    /usr/lib/nagios/plugins/check_by_ssh -p $ARG1$ -l nagios -t 30 -i /var/lib/nagios/.ssh/id_ed25519 -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/zulip_zephyr_mirror/check_user_zephyr_mirror_liveness'
 | 
					        command_line    /usr/lib/nagios/plugins/check_by_ssh -p $ARG1$ -l nagios -t 30 -i /var/lib/nagios/.ssh/id_ed25519 -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/zulip_app_frontend/check_cron_file /var/lib/nagios_state/check_user_zephyr_mirror_liveness'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define command{
 | 
					define command{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,9 @@ states: Dict[str, int] = {
 | 
				
			|||||||
    "UNKNOWN": 3,
 | 
					    "UNKNOWN": 3,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					state_file_path = "/var/lib/nagios_state/check_user_zephyr_mirror_liveness"
 | 
				
			||||||
 | 
					now = timezone_now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def report(state: str, short_msg: str, too_old: AbstractSet[Any] = set()) -> None:
 | 
					def report(state: str, short_msg: str, too_old: AbstractSet[Any] = set()) -> None:
 | 
				
			||||||
    too_old_data = ""
 | 
					    too_old_data = ""
 | 
				
			||||||
@@ -46,13 +49,14 @@ def report(state: str, short_msg: str, too_old: AbstractSet[Any] = set()) -> Non
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
            for user in too_old
 | 
					            for user in too_old
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    print(f"{state}: {short_msg}{too_old_data}")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    with open(state_file_path + ".tmp", "w") as f:
 | 
				
			||||||
 | 
					        f.write(f"{now}|{states[state]}|{state}|{short_msg}{too_old_data}")
 | 
				
			||||||
 | 
					    os.rename(state_file_path + ".tmp", state_file_path)
 | 
				
			||||||
 | 
					    print(f"{state}: {short_msg}{too_old_data}")
 | 
				
			||||||
    exit(states[state])
 | 
					    exit(states[state])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
now = timezone_now()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
all_users = UserActivity.objects.filter(
 | 
					all_users = UserActivity.objects.filter(
 | 
				
			||||||
    query__in=["get_events", "/api/v1/events"], client__name="zephyr_mirror"
 | 
					    query__in=["get_events", "/api/v1/events"], client__name="zephyr_mirror"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,4 +32,12 @@ class zulip_ops::prod_app_frontend_once {
 | 
				
			|||||||
    mode   => '0644',
 | 
					    mode   => '0644',
 | 
				
			||||||
    source => 'puppet:///modules/zulip_ops/cron.d/check_send_receive_time',
 | 
					    source => 'puppet:///modules/zulip_ops/cron.d/check_send_receive_time',
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  file { '/etc/cron.d/check_user_zephyr_mirror_liveness':
 | 
				
			||||||
 | 
					    ensure => file,
 | 
				
			||||||
 | 
					    owner  => 'root',
 | 
				
			||||||
 | 
					    group  => 'root',
 | 
				
			||||||
 | 
					    mode   => '0644',
 | 
				
			||||||
 | 
					    source => 'puppet:///modules/zulip_ops/cron.d/check_user_zephyr_mirror_liveness',
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user