I am working on code for a webserver.
I am trying to use webhooks to do the following tasks, after each push to the repository:
update the code on the webserver.
restart the server to make my changes take effect.
I know how to make the revision control run the webhook.
Regardless of the specifics of which revision control etc. I am using, I would like to know what is the standard way to create a listener to the POST call from the webhook in LINUX.
I am not completely clueless - I know how to make a HTTP server in python and I can make it run the appropriate bash commands, but that seems so cumbersome. Is there a more straightforward way?
Setup a script to receive the POST request ( a PHP script would be enough )
Save the request into database and mark the request as "not yet finished"
Run a crontab and check the database for "not yet finished" tasks, and do whatever you want with the information you saved into database.
This is definately not the best solution but it works.
You could use IronWorker, http://www.iron.io, to ssh in and perform your tasks on every commit. And to kick off the IronWorker task you can use it's webhook support. Here's a blog post that shows you how to use IronWorker's webhooks functionality and the post already has half of what you want (it starts a task based on a github commit): http://blog.iron.io/2012/04/one-webhook-to-rule-them-all-one-url.html
Related
I have a number of microservices I want to monitor for uptime. I would like to make a call to each microservice to evaluate its state. If the call succeeds, I know the application is "UP".
For an overly simplified use case, say I have the following three calls below. I want to make a call to each of them every 10 minutes. If all three respond with a 200, I want to modify an HTML file with the word "UP", otherwise the file should have the word "DOWN".
GET /api/movies/$movieId
POST /api/movies
DELETE api/movies/$movieId
Is Express/Node.js a good framework for this lightweight app? If so, can someone point me to a GitHub stub that can get me started? Thanks!
Both Express and Restify would be fine for this sort of example if they're simply API's. The clincher would be your note about returning HTML.
I want to modify an HTML file with the word "UP", otherwise the file should have the word "DOWN".
This would be more appropriate for Express as it allows you to use libraries like handlebars, mustache, pug, etc to do this HTML transformation.
You can use a scheduled job to check the status of your three applications, store that latest status check somewhere (a database, flat file, etc). Then a request to an endpoint such as /status on this new service would look up the latest status check, and return some templated HTML (using something like handlebars).
Alternatively, if you're comfortable with a bit of Bash you could probably just use linux / unix tooling to do this if you don't care about up-time history or further complexities.
You could setup apache or nginx to serve a file on the /status endpoint. Then use a cron job to ping all your health check URL's. If they all return without errors, you can update the file being served by nginx to say "UP", and if any errors are returned change the text to "DOWN".
This unix approach can also be done on windows if that's your jam. It would be about as light weight as you can get, and very easy to deploy and correct, but if you want to expand this application significantly in the future (storing up time history for example) you may wish to fall back to Express.
Framework? You kids are spoilt. Back when I was a lad all this round here used to be fields...
Create two html template files for up and down, make them as fancy as you want.
Then you just need a few lines of bash run every 10 minutes as a cron job. As a basic example, create statuspage.sh:
#!/bin/bash
for http in GET POST DELETE
do
res=$(curl -s -o /dev/null -w "%{http_code}" -X $http https://$1)
if [ $res -ne 200 ]
then
cp /path/to/template/down.html /var/www/html/statuspage.html
exit $res
fi
done
cp /path/to/template/up.html /var/www/html/statuspage.html
Make it executable chmod +x statuspage.sh and run like this ./statuspage.sh "www.example.com/api"
3 curl requests, stopping as soon as one fails then copying the up or down template to the location of your status page as applicable.
We have a GITlab(8.14) running for collaboration within the company.
I am working on a python script to collect information about merge requests being raised by developers across projects. I can very easily isolate the merge requests using 'git log'
git log --merges
However, I haven't been able to locate the correct command or option to retrieve all the discussion/comments taking place in the Merge Request.
Solution 1: use Gitlab Log System
Have you thought to use the Gitlab Log System instead of using a Git command?
It contains information about all performed requests.... Also you can see all
SQL request that have been performed and how much time it took.
Please take a look here https://docs.gitlab.com/ee/administration/logs.html
So in your Python script of collecting information, you can use queries like that:
SELECT <things> FROM "merge_requests" WHERE <condition>
Solution 2: use Gitlab API
Another way is to directly request Gitlab API to get a list of all notes for a single merge request.
Notes are comments on snippets, issues or merge requests.
like this:
GET /projects/:id/merge_requests/:merge_request_id/notes
The complete API reference for merge request notes is available here.
Does this help you?
Is it possible for GitHub to trigger a new test deployment when a pull request is submitted? I'd like for it to create a new folder on the server (Azure preferred) so that a test URL (e.g. http://testserver.com/PR602/) is generated that we can refer to in the pull request.
This would allow anyone to test a pull request without having to clone the repo, check out the branch, and build it locally.
In my initial research I found that Travis CI can deploy all branches, but I'm not clear how this would be triggered. Do I have to write a custom app that's triggered by pull request web hooks? I'm hoping someone has discovered a simpler method.
Do I have to write a custom app that's triggered by pull request web hooks?
Yes, or find someone else who has happened to have written the exact webhook handler you need.
Writing a webhook handler isn't terribly much work. If you don't want to integrate it with your current app, you can use a micro-framework like Flask to do this in only a few lines of code.
Coming back to this in 2022, there is now also the option of Github Actions, which is a first-party CI service. Actions provides a framework for defining what things to do when certain triggers happen, and there's an extensive marketplace of drop-in components, so you may be able to do all of your triggering of other systems without writing any custom code or running a webserver to listen to webhooks.
I'm working on a webshop in which it should be possible to subscribe to a service for a monthly 20$ fee in return.
I've made a script in a c# usercontrol which will be called monthly by umbraco scheduled task command:
<task log="true" alias="test60" interval="60" url="http://mysite/umbraco/subscriptionPayment.aspx"/>
For that I have two questions.
1) Where should I put the usercontrol in order to make it unaccessible for the public but accessible for the umbraco task command? It is very important that the script can only be accessed by local server commands.
2) I would like the script to log a file each time a transaction is made. I'm using the following script:
File.AppendAllText("paymentlog.txt",
"Transaction "+transactionNumber.ToString() +" sucessfully executed at "+DateTime.Now.ToString() + Environment.NewLine);
I just don't know which path I should give to the paymentlog.txt file since handling real paths in umbraco seems kind of obscure to me. I would like the paymentlog.txt file to be placed in the root umbraco folder. How do I do that?
Thanks in advance (I'm running umbraco 4.8 and uCommerce 2.6.1).
Best regards,
Brinck10
The task scheduler in umbraco isn't very reliable and this sounds like a crucial to your businness so i would probably try to use the build in scheduler in Windows on your server to do the processing.
That being said. In regards to marking the tasks scheduler approach a little more secure you could make the URL you are calling only accessible on localhost/127.0.0.1 and use localhost address in your task configuration.
You can make a call to the user service to verify that the caller is logged in. Following code will achieve that:
using UCommerce.Infrastructure;
using UCommerce.Security;
var authService = ObjectFactory.Instance.Resolve<IAuthenticationService>();
if (authService.IsAuthenticated())
{
// do secure code here
}
In my application i need to use tropo application with node.js to send,receive message and call and answer phone calls.I saw the documentation but i didn't get any idea.Can anyone help me.
Disclaimer - I have never worked with tropo, but this is how I understand it works:
You write a script that tropo can parse, in most languages, to perform some function.
You link up that script to a number using tropo's web interface.
You / a client phones that number, tropo fetches your script and executes it.
Here is a full walkthrough of how everything above works: https://www.tropo.com/docs/scripting/creating_first_application.htm
NOW, if you want your script to do dynamic things, you need to host it yourself. For this you can use node.js:
You write a script that changes based on time / user data in node.js
You link up the script using tropo's web interface.
When someone calls / texts the number, tropo now fetches the dynamic script from your node.js server.
This node.js api can be used to write scripts on your node server: https://github.com/tropo/tropo-webapi-node, https://www.tropo.com/docs/webapi/new_tropo_web_api_overview.htm
Finally, you might want to dynamically create different scripts for different users and hook them up to individual numbers. At this point you use the REST API to automate the "number hooking up work" you used to have to do manually on tropo's website. You can use any node REST client, like request to do this. Here are the API docs: https://www.tropo.com/docs/rest/rest_api.htm