mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-24 04:54:00 -07:00
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.17) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.10) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.12) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.7) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
* Adjust all __future__ imports: for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i; done * Remove all UTF-8 encoding specifications for Python source files: for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i; done * Remove __metaclass__ = type: for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do sed -e '/^__metaclass__ = type/d' -i $i; done
102 lines
2.3 KiB
Python
102 lines
2.3 KiB
Python
#!/usr/bin/python
|
|
|
|
# Copyright (c) 2017, Ansible Project
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
DOCUMENTATION = r"""
|
|
module: logentries_msg
|
|
short_description: Send a message to logentries
|
|
description:
|
|
- Send a message to logentries.
|
|
extends_documentation_fragment:
|
|
- community.general.attributes
|
|
attributes:
|
|
check_mode:
|
|
support: full
|
|
diff_mode:
|
|
support: none
|
|
options:
|
|
token:
|
|
type: str
|
|
description:
|
|
- Log token.
|
|
required: true
|
|
msg:
|
|
type: str
|
|
description:
|
|
- The message body.
|
|
required: true
|
|
api:
|
|
type: str
|
|
description:
|
|
- API endpoint.
|
|
default: data.logentries.com
|
|
port:
|
|
type: int
|
|
description:
|
|
- API endpoint port.
|
|
default: 80
|
|
author: "Jimmy Tang (@jcftang) <jimmy_tang@rapid7.com>"
|
|
"""
|
|
|
|
RETURN = """#"""
|
|
|
|
EXAMPLES = r"""
|
|
- name: Send a message to logentries
|
|
community.general.logentries_msg:
|
|
token: 00000000-0000-0000-0000-000000000000
|
|
msg: "{{ ansible_hostname }}"
|
|
"""
|
|
|
|
import socket
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
|
def send_msg(module, token, msg, api, port):
|
|
|
|
message = "{0} {1}\n".format(token, msg)
|
|
|
|
api_ip = socket.gethostbyname(api)
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.connect((api_ip, port))
|
|
try:
|
|
if not module.check_mode:
|
|
s.send(message)
|
|
except Exception as e:
|
|
module.fail_json(msg="failed to send message, msg=%s" % e)
|
|
s.close()
|
|
|
|
|
|
def main():
|
|
module = AnsibleModule(
|
|
argument_spec=dict(
|
|
token=dict(type='str', required=True, no_log=True),
|
|
msg=dict(type='str', required=True),
|
|
api=dict(type='str', default="data.logentries.com"),
|
|
port=dict(type='int', default=80)),
|
|
supports_check_mode=True
|
|
)
|
|
|
|
token = module.params["token"]
|
|
msg = module.params["msg"]
|
|
api = module.params["api"]
|
|
port = module.params["port"]
|
|
|
|
changed = False
|
|
try:
|
|
send_msg(module, token, msg, api, port)
|
|
changed = True
|
|
except Exception as e:
|
|
module.fail_json(msg="unable to send msg: %s" % e)
|
|
|
|
module.exit_json(changed=changed, msg=msg)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|