Мониторинг транков Asterisk с уведомлением о проблеме по почте

Хочу привести пример php скрипта, который я иногда использую для мониторинга транков. Я помещаюего в cron с интервалом в 15 минут. После срабатывания он проверит транки. Если есть не работающий – дает паузу в 20 секунд. Снова проверяет состояние транков. Если ничего не изменилось – перегружаем модуль chan_sip в asterisk. И если это не могло – шлем email с отчетом по почте, указанной в переменной $report_email.
Скрипт не мой лично – но нареканий в работе у меня нет.

#!/usr/bin/php -q
<!--?php 

// set up the email address to receive the alert email
$report_email = '[email protected]';

$state = wots_up();
echo $state;

if ($state == 'ok')
{
 //если все нормально - прекращаем выполнение
 exit;
}
else
{
 //если нет - пауза в 20 секунд и снова проверяем
 sleep(20);
 $state = wots_up();
 $have_done = "We have retried in 20 seconds.\r\n";
}

if ($state == 'ok')
{
 //если все нормально - прекращаем выполнение
 exit;
}
else
{
 $have_done .= "Trying to reload the sip channels.\r\n";
 $have_done .= shell_exec('/usr/sbin/asterisk -rx "module reload chan_sip"');
 sleep(20);
 $have_done .= "Reloaded sip channels and waited 20 seconds.\r\n";
 $state = wots_up();
}

if ($state == 'ok')
{
 //wipes the sweat
 exit;
}

$status = "$have_done\r\n====have done above, the current status: ====\r\n$status";

if ($state == 'requesting')
{
 send_alert_email('Trunk has been sending registrating requests', $status);
}
elseif ($state == 'empty')
{
 send_alert_email('Voip trunk registration status is empty', $status);
}
elseif ($state == 'no_auth')
{
 send_alert_email('No Authentication is reported, wrong password?', $status);
}
elseif ($state == 'unregistered')
{
 send_alert_email('We have Unregistered trunk', $status);
}
elseif ($state == 'failed')
{
 send_alert_email('We have Registration failed trunk', $status);
}
elseif ($state == 'auth_sent')
{
 send_alert_email('We have trunk with Auth. Sent status', $status);
}
elseif ($state == 'rejected')
{
 send_alert_email('We have trunk with Rejected status', $status);
}
else
{
 send_alert_email('Trunk status is not registered', "$state\r\n\r\n$status");
}

function wots_up()
{
 global $status;

 //Берем статусы транков
 $status = shell_exec('/usr/sbin/asterisk -rx "sip show registry"');

 if (strlen(trim($status)) == 0)
 {
  return 'empty';
 }

 $lines = explode("\n", str_replace("\r\n", "\n", trim($status)));

 for ($i = 1; $i < count($lines) - 1; $i++)
 {
  //echo "line $i " .  $lines[$i] . "\n";
  if (strpos($lines[$i], 'Request Sent') !== false)
  {
   return 'requesting';
  }
  elseif(strpos($lines[$i], 'No Authentication') !== false)
  {
   return 'no_auth';
  }
  elseif(strpos($lines[$i], 'Unregistered') !== false)
  {
   return 'unregistered';
  }
  elseif (strpos($lines[$i], 'Failed') !== false)
  {
   return 'failed';
  }
  elseif (strpos($lines[$i], 'Auth. Sent') !== false)
  {
   return 'auth_sent';
  }
  elseif (strpos($lines[$i], 'Rejected') !== false)
  {
   return 'rejected';
  }
  elseif (strpos($lines[$i], 'Timeout') !== false)
  {
   return 'timeout';
  }
  elseif (strpos($lines[$i], 'Unknown') !== false)
  {
   return 'unknown';
  }

  $temp = preg_split('/\s+/', $lines[$i]);
  if (!isset($temp[3]))
  {
   return "Can not extract Reg State for this line: " . $lines[$i];
  }
  elseif ($temp[3] <--> "Registered")
  {
   return "Unknown Reg state for this line: " . $lines[$i];
  }
 }

 return 'ok';
}

function send_alert_email($subject, $email_content = '')
{
 global $report_email;
 mail($report_email, $subject, $email_content);
}

?&gt;
Рекомендуем почитать
Zabbix – мониторинг сайта

Я уже написал пару статей о Zabbix. В частности, как настроить мониторинг сети с помощью Zabbix, а также как настроить Читать дальше...

Zabbix – мониторинг загрузки сети и Интернет-канала

Zabbix очень неплохо умеет мониторить канал, ну и оповещать админов о том, что канальчик то проседает. Ну и такие плюшки, Читать дальше...

Учим Zabbix отправлять SMS оповещения

This topic has been discussed on the Net before. But I'd like to show my method. There are two ways Читать дальше...

Бесплатный мониторинг доступности вашего сайта с SMS-уведомлением

В данной заметке я расскажу о способе мониторинга доступности вашего сайта, используя Google Docs и Google Calendar. В данном решении Читать дальше...

Поделиться

229 комментариев к “Мониторинг транков Asterisk с уведомлением о проблеме по почте

  1. Wonderful beat ! I wish to apprentice while you amend your website, how could i subscribe for a blog website?
    The account aided me a acceptable deal. I were tiny bit acquainted of this your
    broadcast offered brilliant transparent concept

  2. Hey, I think your blog might be having browser compatibility issues.
    When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has
    some overlapping. I just wanted to give you a quick heads up!
    Other then that, awesome blog!

  3. Attractive section of content. I just stumbled upon your web site and in accession capital
    to assert that I get in fact enjoyed account your blog posts.
    Any way I’ll be subscribing to your augment and even I achievement you access consistently
    quickly.

  4. Howdy I am so delighted I found your website, I really found you by error, while I was researching on Digg for something
    else, Anyways I am here now and would just like to say thanks a lot for a fantastic post and a all round exciting blog (I also
    love the theme/design), I don’t have time to look over it all at the minute but I
    have saved it and also added in your RSS feeds, so when I have time I will be back to read a great deal more, Please do
    keep up the awesome job.

  5. We are a gaggle of volunteers and starting
    a brand new scheme in our community. Your web site provided us with valuable information to work
    on. You have performed a formidable activity and our whole group will likely be
    thankful to you.

  6. This is very interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your great post. Also, I have shared your site in my social networks!

  7. When I initially commented I clicked the -Inform me when brand-new comments are added- checkbox and also now each time a comment is added I get four e-mails with the exact same comment. Is there any way you can eliminate me from that service? Many thanks!

  8. Great blog post. I find out something more tough on different blogs day-to-day. It will certainly constantly be boosting to read web content from various other authors and practice a something from their shop. I?d prefer to make use of some with the web content on my blog site whether you don?t mind. Natually I?ll give you a web link on your internet blog site. Many thanks for sharing.

  9. Do you have a spam problem on this website; I also am a blogger, and I was wondering your situation; we have created some nice
    practices and we are looking to exchange strategies
    with others, please shoot me an email if interested.

  10. After research study a few of the post on your website now, as well as I genuinely like your method of blogging. I bookmarked it to my book marking web site listing as well as will certainly be inspecting back quickly. Pls take a look at my internet site as well and let me recognize what you think.

  11. Hi, I do think this is an excellent site. I stumbledupon it 😉 I am
    going to return once again since I saved as a favorite it.
    Money and freedom is the best way to change,
    may you be rich and continue to guide other people.

  12. Aw, this was an actually great article. In idea I would love to put in writing similar to this in addition? taking time and real initiative to make a very good article? however what can I state? I hesitate alot and by no means appear to get something done.

  13. Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is valuable and all. Nevertheless think about if you added
    some great graphics or videos to give your posts more, “pop”!
    Your content is excellent but with pics and video clips,
    this website could undeniably be one of the best in its niche.
    Great blog!

  14. My spouse and I stumbled over here coming from a different web address and thought I may as well check things out.
    I like what I see so i am just following you. Look forward to looking at your
    web page repeatedly.

  15. After research a few of the article on your internet site now, and I truly like your way of blog writing. I bookmarked it to my book marking internet site list as well as will certainly be checking back quickly. Pls have a look at my internet site too and let me recognize what you believe.

  16. Hi, I do think this is a great website. I stumbledupon it 😉 I will revisit yet again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to help others.

  17. Aw, this was a truly wonderful message. In suggestion I would love to put in writing such as this additionally? taking some time as well as actual initiative to make a very good write-up? yet what can I state? I procrastinate alot and never seem to get something done.

  18. Hi! I could have sworn I’ve been to this website before but after looking at many of the posts I realized it’s new to me. Nonetheless, I’m definitely happy I stumbled upon it and I’ll be book-marking it and checking back often!

  19. Hi, I do believe this is a great website. I stumbledupon it 😉 I’m going to revisit yet again since i have bookmarked it. Money and freedom is the best way to change, may you be rich and continue to guide others.

  20. You are so awesome! I do not think I have read through something like this before. So good to find another person with unique thoughts on this subject. Seriously.. many thanks for starting this up. This website is one thing that is needed on the web, someone with a bit of originality!

  21. Hi, I do believe your website could possibly be having web browser compatibility issues. Whenever I look at your website in Safari, it looks fine however, if opening in Internet Explorer, it’s got some overlapping issues. I just wanted to provide you with a quick heads up! Apart from that, fantastic website!

  22. I’m more than happy to uncover this web site. I want to to thank you for your time just for this wonderful read!! I definitely liked every part of it and I have you saved to fav to see new information on your site.

  23. I’m more than happy to discover this site. I need to to thank you for ones time due to this fantastic read!! I definitely appreciated every part of it and I have you book marked to look at new things in your site.

  24. When I initially commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I recieve 4 emails with the same comment. Perhaps there is a means you can remove me from that service? Thank you!

  25. Aw, this was a really good post. Spending some time and actual effort to generate a really good article… but what can I say… I put things off a lot and don’t manage to get anything done.

  26. You are so cool! I don’t believe I’ve truly read anything like this before. So wonderful to discover somebody with original thoughts on this subject. Seriously.. thanks for starting this up. This web site is something that is required on the internet, someone with a bit of originality!

  27. This is the perfect blog for anyone who wishes to find out about this topic. You know a whole lot its almost hard to argue with you (not that I personally would want to…HaHa). You definitely put a brand new spin on a topic that’s been written about for many years. Great stuff, just excellent!

  28. After I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on each time a comment is added I recieve four emails with the same comment. Perhaps there is a way you are able to remove me from that service? Thanks!

  29. Having read this I thought it was extremely informative. I appreciate you spending some time and effort to put this informative article together. I once again find myself personally spending a lot of time both reading and posting comments. But so what, it was still worth it!

  30. I must thank you for the efforts you have put in penning this blog. I’m hoping to see the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has motivated me to get my own blog now 😉

  31. I seriously love your website.. Pleasant colors & theme. Did you develop this website yourself? Please reply back as I’m wanting to create my very own website and would love to find out where you got this from or what the theme is called. Appreciate it!

  32. Hi there! This article could not be written any better! Going through this post reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will send this article to him. Fairly certain he’s going to have a very good read. I appreciate you for sharing!

  33. Having read this I thought it was rather informative. I appreciate you finding the time and energy to put this informative article together. I once again find myself spending a lot of time both reading and commenting. But so what, it was still worth it!

  34. The very next time I read a blog, Hopefully it doesn’t fail me just as much as this one. After all, I know it was my choice to read, but I genuinely thought you would probably have something interesting to say. All I hear is a bunch of complaining about something you can fix if you weren’t too busy seeking attention.

  35. Hi there! This post could not be written any better! Looking at this post reminds me of my previous roommate! He always kept talking about this. I’ll send this information to him. Fairly certain he’s going to have a very good read. Thanks for sharing!

  36. Youre so amazing! I do not expect Ive check out anything similar to this prior to. So great to find somebody with some initial thoughts on this subject. realy thanks for starting this up. this internet site is something that is needed on the web, someone with a little originality. beneficial task for bringing something brand-new to the internet!

  37. I’m more than happy to uncover this great site. I want to to thank you for your time for this fantastic read!! I definitely liked every little bit of it and I have you book marked to check out new things in your website.

  38. I blog often and I seriously thank you for your information. The article has really peaked my interest. I am going to bookmark your blog and keep checking for new information about once a week. I subscribed to your Feed too.

  39. Hello there! This article couldn’t be written much better! Looking at this article reminds me of my previous roommate! He continually kept talking about this. I am going to forward this article to him. Fairly certain he’ll have a great read. I appreciate you for sharing!

  40. I was very pleased to uncover this web site. I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every bit of it and i also have you book marked to see new information in your blog.

  41. I’m very happy to discover this site. I want to to thank you for your time for this fantastic read!! I definitely appreciated every bit of it and I have you saved to fav to look at new information on your blog.

  42. Next time I read a blog, I hope that it does not disappoint me as much as this one. After all, I know it was my choice to read, but I really believed you would have something helpful to talk about. All I hear is a bunch of complaining about something that you could possibly fix if you weren’t too busy searching for attention.

  43. After I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I get 4 emails with the same comment. There has to be a means you can remove me from that service? Many thanks!

  44. Right here is the perfect blog for anybody who really wants to find out about this topic. You know so much its almost tough to argue with you (not that I personally would want to…HaHa). You definitely put a new spin on a topic that has been discussed for decades. Excellent stuff, just excellent!

  45. Hi, I do believe this is a great web site. I stumbledupon it 😉 I’m going to come back once again since I saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide other people.

  46. I must thank you for the efforts you have put in writing this blog. I am hoping to view the same high-grade content from you in the future as well. In fact, your creative writing abilities has motivated me to get my own, personal site now 😉

  47. Having read this I thought it was extremely informative. I appreciate you spending some time and energy to put this information together. I once again find myself spending way too much time both reading and commenting. But so what, it was still worth it!

  48. Howdy, There’s no doubt that your site might be having web browser compatibility issues. When I look at your site in Safari, it looks fine however, if opening in Internet Explorer, it’s got some overlapping issues. I simply wanted to provide you with a quick heads up! Aside from that, great site!

  49. I seriously love your site.. Very nice colors & theme. Did you make this website yourself? Please reply back as I’m trying to create my own personal website and would love to know where you got this from or exactly what the theme is called. Thanks!

  50. When I initially commented I clicked the -Inform me when new comments are included- checkbox and also currently each time a comment is included I obtain 4 emails with the exact same comment. Exists any way you can eliminate me from that solution? Many thanks!

  51. When I initially commented I clicked the -Notify me when brand-new comments are included- checkbox and also currently each time a remark is included I get 4 emails with the same comment. Is there any way you can remove me from that service? Many thanks!

  52. I’m more than happy to discover this page. I need to to thank you for your time for this particularly fantastic read!! I definitely appreciated every little bit of it and I have you book marked to check out new stuff on your site.

  53. An outstanding share! I’ve just forwarded this onto a colleague who had been conducting a little homework on this. And he in fact ordered me dinner simply because I discovered it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanks for spending time to discuss this issue here on your internet site.

  54. Oh my goodness! Incredible article dude! Many thanks, However I am experiencing troubles with your RSS. I don’t know the reason why I can’t subscribe to it. Is there anybody having the same RSS issues? Anybody who knows the answer can you kindly respond? Thanx!!

  55. I absolutely love your site.. Great colors & theme. Did you create this site yourself? Please reply back as I’m wanting to create my very own website and want to know where you got this from or exactly what the theme is named. Kudos!

  56. After I originally left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and now every time a comment is added I receive 4 emails with the exact same comment. There has to be a means you are able to remove me from that service? Kudos!

  57. An impressive share! I have just forwarded this onto a friend who was doing a little research on this. And he in fact ordered me dinner simply because I stumbled upon it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanks for spending time to talk about this topic here on your internet site.

  58. Hi, I do think your web site may be having web browser compatibility problems. When I take a look at your site in Safari, it looks fine however, if opening in Internet Explorer, it’s got some overlapping issues. I merely wanted to give you a quick heads up! Apart from that, great blog!

  59. This is the perfect website for everyone who hopes to find out about this topic. You realize a whole lot its almost hard to argue with you (not that I really would want to…HaHa). You definitely put a fresh spin on a subject which has been written about for ages. Excellent stuff, just excellent!

  60. Can I just say what a relief to find somebody who actually knows what they’re discussing on the net. You actually know how to bring an issue to light and make it important. More and more people have to check this out and understand this side of your story. I was surprised that you’re not more popular since you most certainly have the gift.

  61. Next time I read a blog, I hope that it won’t fail me just as much as this one. After all, Yes, it was my choice to read, but I truly believed you’d have something interesting to say. All I hear is a bunch of crying about something that you could possibly fix if you weren’t too busy searching for attention.

  62. I truly love your blog.. Pleasant colors & theme. Did you create this amazing site yourself? Please reply back as I’m trying to create my own blog and would love to know where you got this from or what the theme is called. Appreciate it!

  63. You are so interesting! I do not believe I’ve read something like this before. So nice to find somebody with a few unique thoughts on this subject matter. Really.. many thanks for starting this up. This web site is one thing that is required on the web, someone with some originality!

  64. I?m pleased, I need to say. Really hardly ever do I run into a blog that?s both enlightening as well as entertaining, as well as let me tell you, you have struck the nail on the head. Your idea is impressive; the issue is something that not nearly enough people are speaking wisely around. I am very satisfied that I stumbled across this in my search for something relating to this.

  65. You are so cool! I do not suppose I have read anything like that before. So wonderful to discover someone with some original thoughts on this subject. Really.. thank you for starting this up. This website is one thing that’s needed on the web, someone with some originality!

  66. Right here is the right webpage for anyone who really wants to understand this topic. You realize so much its almost tough to argue with you (not that I actually will need to…HaHa). You definitely put a fresh spin on a subject that has been written about for many years. Wonderful stuff, just excellent!

  67. I really love your website.. Pleasant colors & theme. Did you build this website yourself? Please reply back as I’m wanting to create my very own site and would like to know where you got this from or what the theme is called. Many thanks!

  68. Nice post. I learn something totally new and challenging on websites I stumbleupon every day. It’s always helpful to read through articles from other writers and practice a little something from other web sites.

  69. Next time I read a blog, I hope that it does not disappoint me as much as this one. After all, I know it was my choice to read, nonetheless I really believed you would probably have something useful to talk about. All I hear is a bunch of moaning about something you could possibly fix if you were not too busy seeking attention.

  70. I was curious if you ever considered changing the structure of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two pictures. Maybe you could space it out better?

  71. Fantastic blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own website soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m totally confused .. Any suggestions? Appreciate it!

  72. I’m amazed, I have to admit. Rarely do I encounter a blog that’s both equally educative and engaging, and without a doubt, you’ve hit the nail on the head. The issue is an issue that not enough men and women are speaking intelligently about. I’m very happy I stumbled across this in my search for something regarding this.

  73. The next time I read a blog, I hope that it won’t fail me as much as this particular one. I mean, Yes, it was my choice to read through, but I actually believed you’d have something helpful to say. All I hear is a bunch of whining about something you could fix if you weren’t too busy looking for attention.

  74. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your site when you could be giving us something informative to read?

  75. Simply wish to say your article is as surprising.
    The clarity in your put up is just cool and that i can suppose
    you are an expert on this subject. Well together with your
    permission allow me to seize your RSS feed to keep up to date with imminent post.
    Thanks one million and please continue the rewarding work.

  76. I would like to thank you for the efforts you’ve put in penning this site. I’m hoping to see the same high-grade blog posts by you later on as well. In fact, your creative writing abilities has encouraged me to get my own blog now 😉

  77. Good post. I learn something totally new and challenging on sites I stumbleupon every day. It will always be helpful to read through articles from other writers and practice a little something from their sites.

  78. I really love your blog.. Great colors & theme. Did you develop this web site yourself? Please reply back as I’m hoping to create my own personal website and would love to learn where you got this from or just what the theme is named. Cheers!

  79. I must thank you for the efforts you have put in penning this site. I really hope to view the same high-grade blog posts by you later on as well. In fact, your creative writing abilities has inspired me to get my own, personal website now 😉

  80. Can I just say what an alleviation to find somebody who actually understands what theyre discussing on the web. You most definitely understand exactly how to bring an issue to light and make it essential. More individuals need to read this and recognize this side of the tale. I angle think youre not a lot more prominent because you definitely have the gift.

  81. Next time I read a blog, I hope that it won’t disappoint me as much as this particular one. I mean, I know it was my choice to read, nonetheless I genuinely believed you would have something interesting to talk about. All I hear is a bunch of complaining about something you can fix if you weren’t too busy looking for attention.

  82. An interesting discussion is worth comment. I think that you should write more on this issue, it may not be a taboo subject but generally people don’t talk about such subjects. To the next! Best wishes!!

  83. Hello there! This post could not be written much better! Reading through this article reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will forward this article to him. Fairly certain he’s going to have a good read. Thanks for sharing!

  84. This is the right blog for anybody who would like to understand this topic. You realize a whole lot its almost tough to argue with you (not that I personally will need to…HaHa). You definitely put a brand new spin on a subject that’s been written about for decades. Excellent stuff, just excellent!

  85. When I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on every time a comment is added I get four emails with the same comment. Is there an easy method you can remove me from that service? Thanks!

  86. Hi, I do think this is an excellent web site. I stumbledupon it 😉 I may come back yet again since i have book marked it. Money and freedom is the best way to change, may you be rich and continue to guide others.

Оставить ответ

Ваш адрес email не будет опубликован. Обязательные поля помечены *