@@ -23,30 +23,32 @@ class ServerStatusController extends Controller
2323 public static function check_server_status ()
2424 {
2525 $ serverxml = CRAFT_BASE_PATH ."/storage/notification/server.xml " ;
26- $ SystemXml = CRAFT_BASE_PATH ."/storage/notification/server .xml " ;
26+ $ SystemXml = CRAFT_BASE_PATH ."/storage/notification/system .xml " ;
2727 if (!file_exists ($ SystemXml ) || !file_exists ($ serverxml ))
2828 {
2929 syslog (1 ,"Required file doesnot exist " );
3030 exit ;
3131 }
32-
3332 $ xml = simplexml_load_file ($ SystemXml );
34- $ SystemSlack = $ xml ->Server ->Slack ;
35- $ SystemEmail = $ xml ->Server ->Email ;
33+ $ SystemSlack = ( array ) $ xml ->Server ->Slack ;
34+ $ SystemEmail = ( array ) $ xml ->Server ->Email ;
3635 $ serverXml = simplexml_load_file ($ serverxml );
37-
3836 foreach ($ serverXml as $ server ) {
39- $ ip =gethostbyname ($ server ->server_ip );
37+ $ ip =gethostbyaddr ($ server ->server_ip );
4038 $ fp = @fsockopen ($ ip , (int )$ server ->port , $ err , $ errstr );
4139 if (!$ fp ) {
42- $ data = ['text ' =>'Service running on port ' .$ server ->server_port .' is Offline ' ];
43- ServerNotificationService::UpdateServerStatus ($ server ->id , 0 );
44- SendNotificationMessageService::sendSlackMessage (json_encode ($ data ), $ server ->port , $ SystemSlack );
45- SendNotificationMessageService::sendEmail ($ data , $ SystemEmail );
40+ $ data = ['text ' =>'Service running on port ' .$ server ->port .' is Offline ' ];
41+ ServerNotificationService::UpdateServerStatus ((int )$ server ->id , 0 );
42+ if (sizeof ($ SystemSlack )<0 ) {
43+ SendNotificationMessageService::sendSlackMessage (json_encode ($ data ),$ server ->port ,$ SystemSlack [0 ]);
44+ }
45+ if (sizeof ($ SystemEmail )<0 ) {
46+ SendNotificationMessageService::sendEmail ($ data ,$ SystemEmail [0 ]);
47+ }
4648
4749 }else
4850 {
49- ServerNotificationService::UpdateServerStatus ($ server ->id , 1 );
51+ ServerNotificationService::UpdateServerStatus (( int ) $ server ->id , 1 );
5052 }
5153 }
5254
0 commit comments