Mattermost and Powershell - a huge force, or small automation on their own

    Immediately make a reservation - I work in a company that is not directly connected with IT, so the budget for IT is small. Accordingly, many programs and related amenities are not available to us, so we have to do as we can. And when in the company, in addition to the IT department, there are several hundred users who hardly distinguish the monitor from the mouse, the work becomes like a separate quest.

    Therefore, written by me will be rather useful for admins in small companies .

    Many (or not many) have heard of such a wonderful tool as the Mattermost .
    For those who have not heard - this is such a Slack, but only self-hosted. Inside the company, general chat is the most useful thing.

    It is put elementary, if desired, it is very easy to screw a bot (I, for example, use Hubot), which can wrap up all sorts of task alerts from redmaying or monitoring, and automate some business processes that can be turned into question-answer script is worth a lot .

    Everyone is comfortable this chat, but there is one thing but. In fact, not one, but the lack of a normal structured list of users simply kills. You can, of course, use Openfire + Miranda, but the presence of the Mattermost client for phones with push-notification capabilities outweighs all these disadvantages. Since the number of users is not a dozen, the number of departments is also not two, sometimes the question arises - who is working today at the reception in a remote branch? Which one is online? How beautiful and accessible to convey to the average user this information in one place is another question. To draw a spreading tree of options for requests and answers for a chatbot is still something for fun, so I present a hack on the knee specifically for such an occasion.

    The service for Mattermost, written by the convenience of running various powershell scripts from slash / custom commands. In fact, you can use it for different needs, referring to it by url, but I wrote it in order to draw buttons in the little chick. Everyone loves buttons, even seals and aunts from accounting. Well, any Windows admin should be able to write on PowerShell, so it’s useful!

    Approximate work looks like this: The

    service is designed to work on Windows systems, with Powershell v3 +. To run it, you need rights to run PowerShell scripts and open a socket. There is no authentication in the script, so I do not advise you to write something destructive in the configs and put a bare booty on the Internet. On the other hand, you can prescribe the path of a genuine, but it is an amateur.

    The service itself consists of the script itself, and a file config, which specifies the scripts to be run and the data transmitted to the input ( described in the documentation, clause 8 ).

    Entries in the config


    means that when the url / script is accessed, the Dummy-Script.ps1 script will be launched, located in the same directory as ButtonCommander, with the incoming text, team_domain, user_name variables.

    The service receives data from scripts and sends them to the channel from which the request came. If the data came in the form of JSON, then the conversion to a simple message does not occur, and the original JSON is sent to the Mattermost - this is how the buttons are made.

    The script can be stopped or re-read the config file, too, by contacting a special url. But in other, the description and installation are described directly in the repository, so I will not copy-paste. The script was run-in, and laid out in the working version. It works without failures for quite a long time.

    Link to the repository.

    PS: Author is not a writer or a programmer, but a broad profile obstetrician, therefore he writes as best he can.
    PPS: It's all about Team Edition, which (oh pain, pain!) Has no ldap authorization. I’m going out of the position of replacing the login page with my own (nginx + python,), but that work is so monstrous that I consider it a crime to upload it.

    Also popular now: