Read Nagios Notification using php - php

How can I read response from a remote server using Nagios Notification? I'm new to this Nagios Notification System.
The only data from the server side is, they are pushing data in this format:
/usr/bin/curl --url http://mywebpage.com/TicKeTREder.php? --data-urlencode "eventType=Nagios Notification" --data-urlencode "message=$NOTIFICATIONTYPE$#$LONGDATETIME$#$SERVICEDESC$#$HOSTALIAS$#$SERVICESTATE$#$SERVICEOUTPUT$#$CONTACTEMAIL$#$NOTIFICATIONISESCALATED$"
I've tried searching. But no results found.
What I need is read those tickets from Nagios notification system with my TicKeTREder.php page.
Is there any plugin to read these data using php.
Issue solved since the problem was not with the program side.

You get the message with
$message = $_REQUEST['message'];
You can split the information parts with:
$infoArray = explode('#', $message);
Then $infoArray[0] holds the notification type and so on.

you will get data from nagios as a string where all the server /service details are seprated with hash(#). You can split these details by :
$Array = explode('#', $message);

Related

FacebookMessenger API send messages but don't get

I'm currently developing a messenger BOT where the BOT is on an server A hidden with a vpn.
So I have a server B which gets the request and sends it to the server A.
The problem is that I'm able to send messages and quick replies with A when I send an http request directly. But A never get curl request from B.
The second problem and the main, is that the first server don't 'always' get the request from the Facebook server.
In my code I copy past the content of php://input to text.txt on both server A and B to investigate
if (($response = file_get_contents("php://input")) === FALSE) {
file_put_contents("text.txt", "error get");return false;
}
if (($json = json_encode($response)) === FALSE) {
file_put_contents("text.txt", "decode");return false;
}
file_put_contents("text.txt", $json);
when I do curl -X POST -H "Content-Type: application/json" -d '{"name": "linuxize", "email": "linuxize#example.com"}' myserver.com I always get the data on server B
But when I send message on messenger, and that I should get an HTTP request to B, I don't get the request OR I get an older request which is always with the same content except the "time". But the timestamp is the same.
If anyone understand/know why I don't always get the right data in php://input it would be awesome

Piping email to PHP app

I have a PHP app that I built using the Slim routing framework. The app needs to send dynamic emails from orders so that users can just respond to those emails and the response goes right back into the app (stored in MySQL). I can easily create the dynamic address per order and that goes out just fine. My problem is getting it back.
I setup a subdomain (mailer.example.com) and in cPanel I setup a forwarder to catch all mail to that subdomain and forward it to a specific PHP file. That php file reads stdin and grabs the mime message and currently writes it to a file:
#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd))
{
$email .= fread($fd, 1024);
}
fclose($fd);
$filename = "mail_".date("mdYHis").rand(1,99999999);
file_put_contents("mailfiles/".$filename, $email);
header("Location: http://www.example.com/public/mailer/process/".$filename);
As you can see, at the end I would like to forward this to my actual app which has all the database calls and other routines to process the email. But I don't know how to get the request into the app. It seems to ignore the header call above.
Am I doing this all wrong or should I just do all the processing I need in this script? I realize that would maybe be the easiest path forward but I'm also trying to use a mail parse library that fits nicely in my app.
Not sure if that all makes sense. Let me know what other info you need.
I think what you're looking to do isn't to return an HTTP response with a Location header, but rather initiate an HTTP request to your web server.
In that case, you should replace your header() call with:
$ch = curl_init('http://localhost/public/mailer/process/' . $filename);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
Note that your script (the one called to save the mail contents) will wait for your app to finish processing the request. If this is an issue for you, you'll need to use a technique to run PHP processes in the background.
You can read a mailbox with php and parse the emails that way.
// To connect to a POP3 server on port 110 on the local server, use:
$mbox = imap_open ("{localhost:110/pop3}INBOX", "user_id", "password");
I would not, create a custom reply-email/mailbox, per order, instead add the order to the subject as a reference. That way you only need to parse one mailbox.
Find the imap functionality here

PerfectCURL - How to make the following call?

I am using PerfectSwift for a RESTful API to bridge our TeamCity build server and HipChat; however I am stuck at a point whereby I am unable to post to the HipChat backend using Perfect's cURL wrapper.
The command I am trying to mimic is:
curl -d '{"color":"green","message":"My first notification (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>
I currently have the following code in my Perfect program:
let curl = CURL(url: "https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>")
curl.setOption(CURLOPT_POST, int: 1)
curl.setOption(CURLOPT_POSTFIELDS, s: "{\"color\":\"green\",\"message\":\"My first notification (yey)\",\"notify\":false,\"message_format\":\"text\"}")
curl.setOption(CURLOPT_HTTPHEADER, s: "[Content-Type:application/json]")
curl.perform { (code, header, body) in
}
However, the message never gets to HipChat, or, if it does, it's not in a readable format.
When I paste the first command into terminal, everything works as expected.
From my understanding, this uses a similar system to PHP, and I am therefore including the PHP tag as I feel PHP developers may be able to offer advice if I am using the wrong CURLOPTs etc...
Thanks in advance.

How to use ChromePushNotification in PHP

I need to push notification to user , when new task is assigned to the user, I am planning to use "ChomePushNotification" , but i could not understand how to use it in php to invoke notification..
https://storage-cdn.realtime.co/chrome-push/index.html
Can anyone give me the overview how to use this in PHP , to invoke notification if a record inserted in a table "Task" with agent_id =123, i need to send notification to user "123".. "NEW TASK ASSIGNE.."
The first step is to use javascript to give the user the option to subscribe to the push notifications...
if ('serviceWorker' in navigator) {
console.log('Service Worker is supported');
navigator.serviceWorker.register('sw.js').then(function(reg) {
console.log(':^)', reg);
reg.pushManager.subscribe({
userVisibleOnly: true
}).then(function(sub) {
console.log('endpoint:', sub.endpoint);
});
}).catch(function(error) {
console.log(':^(', error);
});
}
The next step is to use cURL to send the request to Google using the following cURL command, either from the command line or by extrapolating it into a PHP cURL command...
curl --header "Authorization: key=AIzaSyAc2e8MeZHA5NfhPANea01wnyeQD7uVY0c" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration\_ids\":[\"APA91bE9DAy6\_p9bZ9I58rixOv-ya6PsNMi9Nh5VfV4lpXGw1wS6kxrkQbowwBu17ryjGO0ExDlp-S-mCiwKc5HmVNbyVfylhgwITXBYsmSszpK0LpCxr9Cc3RgxqZD7614SqDokwsc3vIEXkaT8OPIM-mnGMRYG1-hsarEU4coJWNjdFP16gWs\"]}"
Please note the cURL example is take directly from the Google Developers page at https://developers.google.com/web/fundamentals/getting-started/push-notifications/step-07?hl=en and uses their sample hashes and keys.
For further information you can review the details of how to send push notifications by checking out the Google documentation at https://developers.google.com/web/fundamentals/getting-started/push-notifications/?hl=en

How to use ForceReply in a telegram bot

I'm developing a telegram bot using php and a web hook. All it's fine but sometimes I would like to "wait for a reply" from the user. For example:
If the client write /info without any parameters I would like to show a "usage" message and ask&wait for a ID parameter.
I know there is a property "ForceReply" to force for a reply, but when I set it up nothing happens, and I don't know how to know if the client message its a reply for my question.
Do I have to put my php server on hold? (I think it would be a bad practice) Do I have to whait for a type of message?
Thanks
When you use getUpdates or receive updates via a webhook, the update message will contain a field like reply_to_message field. You can use this to compare it to the message you sent.
If you are running your script via webhooks I would assume that it only executes when it receives a message. If so, I would suggest you use something like memcache/redis to store the message you are expecting a reply for and then when the reply comes, you can compare it to the value stored:
<?php
// This script triggers as a webhook
$message = file_get_contents('php://input');
$message = json_decode($message, true);
$cache = new RedisClient('localhost');
if ($message->reply_to_message == $cache->get('original.message.id'))
{
var_dump('message reply received');
}
The example above is some "pseudo" code that you can use in a webhook to check for a reply to a specific message.

Categories